+ 2

Does anyone know how it works??? need some help please

def add(x, y): return x + y def do_twice(func, x, y): return func(func(x, y), func(x, y)) a = 1 b = 2 print(do_twice(add, a, b))

22nd Apr 2017, 1:34 PM
yannis vanherp
yannis vanherp - avatar
4 Respostas
+ 9
Well, it feeds the do_twice() method with the add() method as both arguments and the function to perform. So you end up with add(add(1,2), add(1,2)), which performs (1+2)+(1+2) Returns 6 obviously.
22nd Apr 2017, 1:38 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 5
*bows*
22nd Apr 2017, 2:08 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 4
No problem. Could you pls mark my answer as best, if it helped you (of course if it really helped you)? Kind of a unique opportunity for me to grab some decent xp at this time ;)
22nd Apr 2017, 1:55 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 2
thnx mate
22nd Apr 2017, 1:41 PM
yannis vanherp
yannis vanherp - avatar