+ 1
Need some help on this
def apply_twice(func, arg): return func(func(arg)) def add_five(x): return x + 5 print(apply_twice(add_five, 10))
4 Answers
+ 1
The output is 20, right?
+ 1
What the apply_twice function does is it calls the function twice, the second time using the result of the first one
First on the inside: add_five(10) returns 15
The outside: add_five(15) returns 20
The 20 returned above then gets printed out
+ 1
What you're trying to do here can be done using a mechanic called "decorator"
Even if it's a little bit more advanced, I'd advise you to take a look on the web