Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #41659 > unrolled thread
| Started by | leonardo selmi <l.selmi@icloud.com> |
|---|---|
| First post | 2013-03-21 19:31 +0100 |
| Last post | 2013-03-21 20:11 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.python
problem with function leonardo selmi <l.selmi@icloud.com> - 2013-03-21 19:31 +0100
Re: problem with function "Alex" <foo@email.invalid> - 2013-03-21 20:11 +0000
| From | leonardo selmi <l.selmi@icloud.com> |
|---|---|
| Date | 2013-03-21 19:31 +0100 |
| Subject | problem with function |
| Message-ID | <mailman.3594.1363894319.2939.python-list@python.org> |
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?
thanks!
[toc] | [next] | [standalone]
| From | "Alex" <foo@email.invalid> |
|---|---|
| Date | 2013-03-21 20:11 +0000 |
| Message-ID | <kifpgq$9v1$1@dont-email.me> |
| In reply to | #41659 |
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.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web