#514 · Functions · Beginner · 25 XP · about 3 min
Write repeat(word, times=2, sep=' ') that returns word repeated times times, with sep between the copies (never at the start or the end).
The parameters times and sep have default values, so they can be left out: called with only a word, the function doubles it with a space in between. If times is 0, the result is an empty string.
repeat('hip') # returns 'hip hip' repeat('ha', 3) # returns 'ha ha ha' repeat('go', 4, sep='-') # returns 'go-go-go-go' repeat('no', times=1) # returns 'no'
First solves only, ranked by stars and then time.