Python is going to be hard

John Gordon gordon at
Wed Sep 3 20:17:27 CEST 2014

In <d9me0ap5s0s28qaeobbh6680gciel6c1og at> Seymore4Head <Seymore4Head at Hotmail.invalid> writes:

> import math
> import random
> import sys

Why are you importing these modules if they're not used?

> b=[]

Likewise b is not used.

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

As you step through the loop, x becomes each successive item in the 'steve'
list.  Therefore, you probably want to print just plain x, not steve[x].

> Traceback (most recent call last):
>   File "C:\Functions\", line 7, in <module>
>     print (steve[x])
> IndexError: list index out of range

There are fewer than 13 items in steve, so when x reaches 13 this error
pops up.

John Gordon         Imagine what it must be like for a real medical doctor to
gordon at    watch 'House', or a real serial killer to watch 'Dexter'.

More information about the Python-list mailing list