473,395 Members | 1,422 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 3252
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: MouseHart | last post by:
I've written a simple program in VB 6.0 to list all my MP3 files. To show them on the screen I used an MSFlexGrid named TextGrid (which is not associated with any table or text file) in the...
3
by: Shyguy | last post by:
I have a MS Word Merge letter that is based on a query. I set up a macro to run the query and then open Word and the merge letter. Word open fine but it can't find the letter. I used RunAPP and...
2
by: Joe Black | last post by:
Hi My database is filling a Word docs with data using bookmarks. My client wants one particular document to print using the lower tray which will hav a special letterhead loaded in it. Is...
3
by: Phil | last post by:
I am looking to set up a hyperlink control on a form to retrieve letters that correspond to a record on a form. That is, there may be 100 form records, and I would like each of those form records...
24
by: Rhino | last post by:
I am dabbling with print CSS for the first time and I need some guidance. The web pages on my site look fine - to my untrained eye - when displayed on the monitor in any of the standard browsers....
2
by: Colin Halliday | last post by:
I have a Word 2003 mail merge main document (form letter) that is linked to another Word document data source for the mail merge. If I open this doc using the Word GUI, it first asks me to...
8
by: Scott | last post by:
I would like to automatically change the first letter to upper case and keep the rest intact of each sentence on a control of a form, i.e., i am going to school. see you in the afternoon. -I am...
12
by: summy | last post by:
Write a program includes ALL the features: 1.Read the specify file sample.txt and then print the contents of the file on screen. 2.Print each lines of the file in reversed order on screen. ...
4
by: zcabeli | last post by:
Hi all, i'm currently struggling to perform the above mentioned replacement. i already know how to catch the first letter in each word and determined if it's regular or capital. however, i...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.