print out each letter of a word

V

vbgunz

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.
 
P

Peter Otten

Gary said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,294
Messages
2,571,511
Members
48,200
Latest member
SCPKatheri

Latest Threads

Top