0

Functional Programming

def apply_twice(func, arg): return func(func(arg)) def add_five(x): return x + 5 print(apply_twice(add_five, 10)) Can someone please explain how the above example returned an answer of 20?

23rd Apr 2018, 5:44 AM
Troy Kelley
Troy Kelley - avatar
3 Answers
+ 1
Thank you Ali and Gordie! I understand it now!
25th Apr 2018, 10:14 PM
Troy Kelley
Troy Kelley - avatar
0
apply_twice(add_five, 10) does the same as add_five(add_five(10)) So it adds 5 to 10 twice, which results in 20.
23rd Apr 2018, 5:48 AM
Ali Zhussupov
Ali Zhussupov - avatar