newbie question on lists, getting an error on basic addition
Aahz
aahz at pythoncraft.com
Sun Mar 31 12:22:31 EST 2002
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.
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
Why is this newsgroup different from all other newsgroups?
More information about the Python-list
mailing list