Re: problem with function

2013-03-22 Thread leonardo
thank you all Il giorno 22/mar/2013, alle ore 00:20, Terry Reedy ha scritto: > On 3/21/2013 2:31 PM, leonardo selmi wrote: > >> i wrote the following code: >> >> def find(word, letter): >> index = 0 >> while index < len(word): >> if word[index] == letter: >> ret

Re: problem with function

2013-03-21 Thread Terry Reedy
On 3/21/2013 2:31 PM, leonardo selmi wrote: 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 Since this is a learning exercise, consider the f

Re: problem with function

2013-03-21 Thread Ian Kelly
On Mar 21, 2013 1:35 PM, "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 > More efficient: def

Re: problem with function

2013-03-21 Thread Alex
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 '

Re: problem with function

2013-03-21 Thread Dave Angel
On 03/21/2013 02:31 PM, 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: n

Re: problem with function

2013-03-21 Thread Chris Angelico
On Fri, Mar 22, 2013 at 5:31 AM, 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 pr

problem with function

2013-03-21 Thread leonardo selmi
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? than