Python is going to be hard

Denis McMahon denismfmcmahon at gmail.com
Wed Sep 3 16:55:27 EDT 2014


On Wed, 03 Sep 2014 14:10:42 -0400, Seymore4Head wrote:

> import math import random import sys b=[]
> steve = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
> for x in steve:
>     print (steve[x])
> 
> Traceback (most recent call last):
>   File "C:\Functions\blank.py", line 7, in <module>
>     print (steve[x])
> IndexError: list index out of range

x is the value, not the index

Try:

steve = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
for x in steve:
    print (x)

or if you want to use the index:

for x in range(len(steve)):
    print (steve[x])


-- 
Denis McMahon, denismfmcmahon at gmail.com



More information about the Python-list mailing list