+ 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))

20th May 2019, 6:02 AM
Janak Sharma
Janak Sharma - avatar
4 Answers
+ 1
The output is 20, right?
20th May 2019, 6:10 AM
Trigger
Trigger - avatar
+ 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
20th May 2019, 6:15 AM
Trigger
Trigger - avatar
+ 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
20th May 2019, 9:06 AM
ThewyShift
ThewyShift - avatar