0

Where did the output 16 come from?

def fun1(func, arg): return func(func(arg)) def fun2(x): return x*x print(fun1(fun2, 2))

13th Jan 2017, 9:42 PM
M Nagi Gedo
M Nagi Gedo - avatar
4 Réponses
+ 3
That code won't run for me as is, but if the 2nd line of fun1 was instead like this: def fun1(func, arg): return func(func(arg)) then 16 is because fun1(fun2, 2) fun2(fun2(2)) fun2(4) 16
13th Jan 2017, 10:08 PM
Potto
Potto - avatar
+ 3
calling fun1(fun2,2) returns fun2(fun2(2)) which evaluates as follows: fun2(2*2) as fun2(x)=x*x fun2(4) finally 4*4 hence 16
14th Jan 2017, 5:36 PM
Sai Kiran Rayapureddy
Sai Kiran Rayapureddy - avatar
+ 2
2×2=4 4×4=16
13th Jan 2017, 9:52 PM
Ihab Taleb
Ihab Taleb - avatar
+ 1
yeah the code is like what u type potto.. sorry my bad
14th Jan 2017, 7:51 AM
M Nagi Gedo
M Nagi Gedo - avatar