+ 1
functions
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)) let me know how does the code works.....
1 Respuesta
0
do_twice in the print statement is called first.
func = add, x=a, y=b
So the return statement in the do_twice will be add(add(5,10),add(5,10))
The inner functions will be called first and the add returns 15 for both functions.
Then it will be add(15,15)
Finally it will add those two and return 30.
30 is returned to the print statement and printed