print out each letter of a word
Peter Otten
__peter__ at web.de
Fri Apr 28 01:58:47 EDT 2006
Gary Wessle wrote:
> I am going through this tut from
> http://ibiblio.org/obp/thinkCS/python/english/chap07.htm
>
> I am getting errors running those 2 groups as below as is from the tut
Next time, please copy and paste the complete "traceback", the error
messages that clutter your screen when something goes wrong.
> index = 0
> while index < len(fruit):
> letter = fruit[index]
> print letter
> index = index + 1
> for char in fruit:
> print char
Does the error message you get look like this?
Traceback (most recent call last):
File "<stdin>", line 1, in ?
NameError: name 'fruit' is not defined
That is because you are using a variable named fruit before you have
assigned a value to it. Put
fruit = "Banana"
before your snippet and everything should work as expected.
Peter
More information about the Python-list
mailing list