problem with function

Alex foo at email.invalid
Thu Mar 21 21:11:06 CET 2013


leonardo selmi 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?
> 

What does your call to find look like? I called it with:

find("word", 'd')

and it returned 3, as expected.

If I call find with

find(word, 'd')

I get an error, as expected, since I have not assigned a string to the
name word.





More information about the Python-list mailing list