(Solved):Write a function: def repeat(string, n, delim) that returns the string repeated n times, separated by the string delim. For example, repeat(“ho”, 3, “) returns “ho, ho, ho” View Answer…

 

Question

Write a function:

def repeat(string, n, delim)

that returns the string repeated n times, separated by the string delim. For example, repeat(“ho”, 3, “) returns “ho, ho, ho”

 

EXPERT ANSWER

The function repeat takes three arguments “string”, “n”, and “delim”. Then using for loop repeats the loop for n-1 times in a range of 0 and n-1. Then concatenate the result, string and delim values #finally returns the result value with string as the

Scroll to top