newbie question on lists, getting an error on basic addition

John Warney john at yahoo.com
Sun Mar 31 16:49:47 EST 2002


Ah, ok, thanks, it works fine now


On 31 Mar 2002 12:22:31 -0500, aahz at pythoncraft.com (Aahz) wrote:

>In article <uggeauc292padb9gk6ghcmghv82g888i3l at 4ax.com>,
>John Warney  <john at yahoo.com> wrote:
>>
>>>>> alist = [1, 2, 3, 4]
>>>>> counter = 0
>>>>> answer = 0
>>>>> alist
>>[1, 2, 3, 4]
>>>>> counter
>>0
>>>>> answer
>>0
>>>>> while counter < 6:
>>... 	answer = answer + alist[counter]
>>... 	counter = counter + 1
>>... 	
>>Traceback (most recent call last):
>>  File "<interactive input>", line 2, in ?
>>IndexError: list index out of range
>>>>> answer
>>10
>
>Add a print counter at the top of your loop and you'll see why.




More information about the Python-list mailing list