[Solved] How return x character of a string WITHOUT *


The question is asking you to create a function(def) named generate_n_chars() that takes an integer(int) value,n and character(char) value,c as parameters. Here, c is any character input by user,lets say user inputs x and n is how many times the character(c) should be printed so lets say user wants it to print 5 times and therefore inputs 5. Then the result would be xxxxx. 5 x’s.

def generate_n_chars(n, c):
        result = ""
        for i in range(n):
            result += c
        return result

    inputChar = input("Enter the character:")
    inputNum = int(input("Enter the number of times " + str(inputChar) + " to be printed:"))
    print("Result: " + str(generate_n_chars(inputNum, inputChar)))

Output:

Enter the character:x
Enter the number of times x to be printed:5
Result: xxxxx

2

solved How return x character of a string WITHOUT *