I'm currently working on recursive function on Think Python, page 44.
It wrote:
"Write a function called
do_n
that takes a function object and a number,n
as arguments,and that calls the given function
n
times."
I found a really good answer from this discussion Text
Okay, now I know how to type the code, but how do I actually run it?
def do_n(f, n):
if n <= 0:
return
f(n)
do_n(f, n-1)
The code like below looks really easy to figure out:
def print_n(s, n):
if n <= 0:
return
print(s)
print_n(s, n-1)
Just need to type Print("Anita", 2)
and the output will be:
Anita
Anita
But the do_n
I can't figure out what to type in order to run the code. I guess I am not familiar with do function.
Can anyone explain it?