+ 1

How can I get 20?

def apply_twice(func, arg): return func(func(arg)) def add_five(x): return x + 5 print(apply_twice(add_five, 10))

27th Dec 2018, 1:58 PM
kokito
4 Respostas
+ 5
apply_twice(add_five, 10) = add_five(add_five(10)) = add_five(10 + 5) = add_five(15) = 15 + 5 = 20
27th Dec 2018, 2:13 PM
Kishalaya Saha
Kishalaya Saha - avatar
+ 2
When you pass add_five and 10 to the function apply_twice Then func acts the same as apply_twice function and arg as 10 So, func(func(arg)) is equivalent to add_five(add_five(10)) Which means:- add_five(10+5)#add_five function called once Or add_five(15)#add_five function called second time Which is equal to 15+5=20 So, output is 20
27th Dec 2018, 2:10 PM
Pulkit Kamboj
Pulkit Kamboj - avatar
+ 2
thank you
27th Dec 2018, 2:12 PM
kokito
+ 2
Sorry slight mistake, just correct ed:)
27th Dec 2018, 2:14 PM
Pulkit Kamboj
Pulkit Kamboj - avatar