acronym program

S

Shawn Minisall

I'm trying to write a program that gets the first letter of every word
of a phrase and prints it on screen. I'm having problems with it. I'm
thinking a for loop would be good since I don't know the exact number of
words the user is going to enter, but after that I get confused. How do
I tell python to just goto the beg of each word in the phrase and
include it in the acronym? Am I on the right track?

for a in string.split(phrase)
acronym = phrase [0]
acronym = acronym + 1

thx
 
P

Paul Rudin

Shawn Minisall said:
I'm trying to write a program that gets the first letter of every word
of a phrase and prints it on screen. I'm having problems with it.
I'm thinking a for loop would be good since I don't know the exact
number of words the user is going to enter, but after that I get
confused. How do I tell python to just goto the beg of each word in
the phrase and include it in the acronym? Am I on the right track?

for a in string.split(phrase)
acronym = phrase [0]
acronym = acronym + 1


How about:

for a in phrase.split():
print a[0]
 
S

Shawn Minisall

That was it! Thanks a lot!

I was also trying to output the acronym in caps so I was entering
string.upper (acronym) like whats in the book and kept getting a
"'tuple' object is not callable" error message. Just for the heck of it
I tried it acronym.upper() and it worked! I thought it could work both
ways?



Paul said:
I'm trying to write a program that gets the first letter of every word
of a phrase and prints it on screen. I'm having problems with it.
I'm thinking a for loop would be good since I don't know the exact
number of words the user is going to enter, but after that I get
confused. How do I tell python to just goto the beg of each word in
the phrase and include it in the acronym? Am I on the right track?

for a in string.split(phrase)
acronym = phrase [0]
acronym = acronym + 1


How about:

for a in phrase.split():
print a[0]
 

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,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top