Answer:
The solution code is written in Python.
- def generateString(char, val):
- output = ""
-
- for i in range(val):
- output += char
-
- return output
-
- print(generateString('a', 7))
Step-by-step explanation:
Firstly, let's create a function generateString() that take two input arguments, char and val.
To generate a string with val number of char, we need a string variable, output, to hold the string value. Let's initialize the output with an empty string (Line 2)
Next, we can create a for loop that will repeat the loop for val number of time (using the range() method) and keep adding the same char to the output string (Line 5).
At last return the output string (Line 7).