[Tutor] IndexError: list index out of range [ Program work fine , but gives this message , guidance requested ]
John Joseph
jjk_saji at yahoo.com
Sun Jan 8 13:36:57 CET 2006
--- Guillermo Fernandez Castellanos
<guillermo.fernandez.castellanos at gmail.com> wrote:
> Hi,
>
> Look at this:
> >>> i=[1,2,3]
> >>> i[len(i)]
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> IndexError: list index out of range
>
>
> This means that I have tried to access an element
> that is out of the
> list, in this case i[3], that is, the 4th element of
> the list.
>
> You are doing the same. You do a
> j in range(len(seats))
> and then you are accessing your list with seats[j]
> and seats[j+1]. What
> happens when j = len(seats)-1 and you call
> seats[j+1]? :-)
>
> It happens indeed the same that in the example I
> gave you first.
>
> Hope it helps. Good luck,
>
Thanks for the advice
But I need to display the results
What should I do in the for loop for this message
to go
my for loop is as
for j in range(length) :
if seats[j] <> seats[j+1]:
print " The Seat", j , "And the seat",
j+1 , "value, which are", seats[j]," and", seats[j+1],
"are not same"
else:
print "The Seats ",j ,"And the seats",
j+1, "Values,", seats[j], "and", seats[j+1], "are
same"
Thanks
Joseph John
___________________________________________________________
Yahoo! Exclusive Xmas Game, help Santa with his celebrity party - http://santas-christmas-party.yahoo.net/
More information about the Tutor
mailing list