470,647 Members | 1,369 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,647 developers. It's quick & easy.

print out each letter of a word

I am going through this tut from
http://ibiblio.org/obp/thinkCS/pytho...ish/chap07.htm

I am getting errors running those 2 groups as below as is from the tut
thanks
index = 0
while index < len(fruit):
letter = fruit[index]
print letter
index = index + 1

or
for char in fruit:
print char
Apr 28 '06 #1
2 3150
what errors are you getting? Could it be an indentation error? I don't
see anything wrong with the script except the value of fruit is
missing. if fruit is a string, it should work like a charm. double
check the length of the fruit with print len(fruit) and check fruit
with print type(fruit) and make sure it really is a 'str'. Also, fruit
has to already exist in the script e.g. 'fruit = apple'. Next time post
your errors too.

Apr 28 '06 #2
Gary Wessle wrote:
I am going through this tut from
http://ibiblio.org/obp/thinkCS/pytho...ish/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
Apr 28 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by MouseHart | last post: by
24 posts views Thread by Rhino | last post: by
8 posts views Thread by Scott | last post: by
1 post views Thread by Korara | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.