Skip to content Skip to sidebar Skip to footer

Simple Function In Python

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('en

Solution 1:

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.

Post a Comment for "Simple Function In Python"