Answer:
Here is the Python program:
def exec_2(f):
f()
f()
def exec_4(f):
exec_2(f)
exec_2(f)
def print_koala():
print("koala")
exec_4(print_koala)
Explanation:
The program works as follows:
First method:
def exec_2(f):
f()
f()
any function that is passed into exec_2() will be executed twice without parameters.
Second method:
def exec_4(f):
exec_2(f)
exec_2(f)
function exec_4(f) takes in a function f as a parameter and executes the function f 4 times using the function exec_2. At first exec_2(f) call the function f is executed twice and and second exec_2(f) call the function f is again executed twice so the function f executes 4 times in total.
Third method:
def print_koala():
print("koala")
a function that prints out the koala once
This function has a print statement which is passed the string koala to print on output screen.
exec_4(print_koala)
function exec_4 is used to print koala four times. This function exec_4 takes as argument the function print_koala() So this works as follows:
exec_4(print_koala)
The body of exec_4 executes as:
exec_2(print_koala)
exec_2(print_koala)
Now at first call to exec_2(print_koala) the program moves to the function exec_2 which executes print_koala() method twice. Since print_koala() method has a print statement print("koala") so this is executed twice:
koala
koala
Now at second call exec_2(print_koala) the program moves to the function exec_2 which executes print_koala() method twice again. Since print_koala() method has a print statement print("koala") so this is executed again twice:
koala
koala
So the output of the entire above program is:
koala
koala
koala
koala
The screenshot of program along with its output is attached.