+ 2

Can anyone explain this code step by step?

Can anyone explain this code step by step? def add(x, y): return x + y def do_twice(func, x, y): return func(func(x, y), func(x, y)) a = 5 b = 10 print(do_twice(add, a, b))

30th Jan 2020, 9:06 AM
Ahmed M. Abbas
Ahmed M. Abbas - avatar
2 Antworten
+ 8
This answer is from Slak: def add(x, y): return x + y Return the sum of the two values passed def do_twice(func, x, y): return func(func(x, y), func(x, y)) func wil be equal to add because of the values passed so you could write this as: return add(add(5,10), add(5,10)) after the function is called: return add(15,15) Tye answer should be 30 30th July 2017, 4:42 PM Slak
30th Jan 2020, 9:46 AM
Lothar
Lothar - avatar
+ 2
Thanks, Lothar for your answer, I appreciate it very much.
30th Jan 2020, 7:55 PM
Ahmed M. Abbas
Ahmed M. Abbas - avatar