[Tutor] help getting acronym to print?

Hugo González Monteverde hugonz-lists at h-lab.net
Mon Sep 26 01:48:46 CEST 2005


Didn't go through everything, but why do you do:

 >    for phrase in string.split(phrase):
 >     acronym = string.upper(phrase[0])


you are iterating with the name of the list? bad juju

try something like

acronym = ""

for word in string.split(phrase):
     acronym = acronym + string.upper(word[0])

then the acronym variable will hold the initial letter to every word

Hugo


Goofball223 at wmconnect.com wrote:
> Hello
> 
> How could I get the following program to output UDP from the user 
> entering user datagram protcol or IP if internet protocla was entered?
> 
> currently it only prints out on letter
> 
> 
> 
> import string
> 
> def main():
> 
> 
>    phrase = (raw_input("Please enter a phrase:"))
> 
>    acr1 = string.split(phrase)
>    print"",acr1 #only using print to see where I am
> 
>    acr2 = string.capwords(phrase)
>    print"",acr2 #only using print to see where I am
>    for phrase in string.split(phrase):
>     acronym = string.upper(phrase[0])
>    
>    print "", acronym
> main()
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor


More information about the Tutor mailing list