more newbie help needed

Fredrik Lundh fredrik at pythonware.com
Mon Nov 14 20:41:11 CET 2005


"john boy" <xray_alpha_charlie at yahoo.com> wrote:

> using the following program:
>
> fruit = "banana"
> index = 0
> while index < len (fruit):
>      letter = fruit[index-1]
>      print letter
>      index= index -1

> after spelling "banana" it gives an error message:
> refering to line 4: letter = fruit[index-1]
> states that it is an IndexError and the string index is out of range
> Anybody know how to fix this?

add "print index" before the "letter =" line to see what your program
is doing, and what index is when you get the error.  then read this:

http://docs.python.org/tut/node5.html#SECTION005120000000000000000

</F> 






More information about the Python-list mailing list