Reputation: 357
My program is to return the string repeated n times separated by the string delim. example repeat("ho",3,",").
def repeat():
string=input("enter a string:")
n=int(input("enter how many times to repeat:"))
delim=(",")
return string,n,delim
print (repeat())
I need to change the output to (hi,hi,hi) instead of this.
enter a string:hi
enter how many times to repeat:3
('hi', 3, ',')
Upvotes: 0
Views: 316
Reputation: 25954
I would recommend using the .join()
method of strings to concatenate your strings. For example:
', '.join(['yo']*4)
Out[4]: 'yo, yo, yo, yo'
There's some other issues in your code, the biggest of which I'd say is that your method repeat()
should not be responsible for taking user input. Move that into main()
and delegate repeat()
to only performing string operations.
Upvotes: 1