[Tutor] Re: Trivia program.
Wolfram Kraus
kraus at hagen-partner.de
Wed Feb 16 11:40:08 CET 2005
. Sm0kin'_Bull wrote:
> Hi, I got a problem with this program.
>
>
> name = raw_input("Hi. What's your name? ")
> called = name * 5
called = ' '.join([name]*5)
> print "\nIf a small child were trying to get your attention, " \
> "your name would become:"
> print called
> When i input the name like "John Goodman"
>
> it prints like...
>
> John GoodmanJohn GoodmanJohn GoodmanJohn GoodmanJohn Goodman
>
> But i want to print it like...
>
> John Goodman John Goodman John Goodman John Goodman John Goodman
>
> How can I do it?
>
[name]*5 gives you a list with five items, every item is name. join uses
a space (' ') to join all items in the list into a new string.
HTH,
Wolfram
More information about the Tutor
mailing list