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))
Explanation:
Firstly, let's create a function <em>generateString()</em> that take two input arguments, <em>char</em> and<em> val.</em>
To generate a string with <em>val </em>number of <em>char</em>, we need a string variable, <em>output,</em> to hold the string value. Let's initialize the <em>output</em> with an empty string (Line 2)
Next, we can create a for loop that will repeat the loop for <em>val</em> number of time (using the <em>range() </em>method) and keep adding the same <em>char</em> to the <em>output</em> string (Line 5).
At last return the <em>output</em> string (Line 7).