0
functions
Can someone please explain the code. i don't want to move forward without fully understanding 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))
3 Answers
+ 4
Does this help?
do_twice(add, a, b)
do_twice(add, 5, 10)
add(add(5, 10), add(5, 10))
add(5 + 10, 5 + 10)
add(15, 15)
15 + 15
30
+ 2
(10 + 5) + (10 + 5) = 30
0
do_twice function is called first
here add is func (understand formal parameters and actual parameters)
so in return statement of do_twice function,add function will be called twice