logo CodeStepByStep logo

repeat_string

Language/Type: Python recursion

Write a recursive function named repeat_string that accepts a string and an integer n as parameters and that returns the string concatenated n times. For example, the call of repeat_string("hello", 3) returns "hellohellohello". Do not use any loops you must use recursion.

Constraints: Your function should throw a ValueError if passed any negative value for n. You are not allowed to construct any structured objects other than strings (no lists, dictionaries, etc.) and you may not use any loops to solve this problem you must use recursion.

Function: Write a Python function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.