+ 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))
4 Respostas
+ 5
apply_twice(add_five, 10)
= add_five(add_five(10))
= add_five(10 + 5)
= add_five(15)
= 15 + 5
= 20
+ 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
+ 2
thank you
+ 2
Sorry slight mistake, just correct ed:)