Answer to Question #163667 in Python for Ray

Question #163667

Write a function called repl that accepts a string and a number of repetitions as parameters and returns the string concatenated that many times. For example, the call repl('hello', 3) should return 'hellohellohello'. If the number of repetitions is zero or less, the function should return an empty string. Do not use the string * operator in your solution; use the concatenation operator.

Sample output:

hello -> hellohellohello



1
Expert's answer
2021-02-15T00:01:39-0500
def repl(str, rep):
    if rep <= 0:
        print("Empty String")
    return (str * rep)



print(repl(str(input("Enter the string: ")), int(input("Enter the number of repetitions: "))))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS