Repeat a string n times and print n lines of it
<p>i've been stuck on a question for some time now:</p>

<p>I'm looking to create a python function that consumes a string and a positive integer. The function will print the string n times, for n lines. I <strong>cannot</strong> use loops, i must only use recursion</p>

<p>e.g.</p>

<pre><code>repeat("hello", 3)

hellohellohello
hellohellohello
hellohellohello
</code></pre>

<p>whenever i try to make a function that does this, the function decreases the length of the string, progressively:</p>

<p>e.g.</p>

<pre><code>repeat("hello", 3)

hellohellohello
hellohello
hello
</code></pre>

<p>here's what my code looks like:</p>

<pre><code>def repeat(a, n):
if n == 0:
    print(a*n)
else:
    print(a*n)
    repeat(a, n-1)
</code></pre>

<p>any help would be appreciated, thanks!</p>

<p>Try this</p>

<pre><code>def f(string, n, c=0):
    if c &lt; n:
        print(string * n)
        f(string, n, c=c + 1)

f('abc', 3)
</code></pre>

python recursion