problem with function

Chris Angelico rosuav at gmail.com
Thu Mar 21 20:40:35 CET 2013


On Fri, Mar 22, 2013 at 5:31 AM, leonardo selmi <l.selmi at icloud.com> wrote:
> hi all,
>
> i wrote the following code:
>
> def find(word, letter):
>     index = 0
>     while index < len(word):
>         if word[index] == letter:
>             return index
>         index = index + 1
>     return -1
>
> if i run the program i get this error: name 'word' is not defined.  how can i solve it?

You'll need to post the whole code of your program. That function
works fine for me. (Though it's somewhat unPythonic code, and in any
case already exists in the standard library.) Tip: Look at the full
traceback from the error. Chances are you'll find the cause of the
error on one of the lines near the end of the trace.

ChrisA



More information about the Python-list mailing list