can anyone explain this | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

can anyone explain this

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 Jul 2017, 2:22 PM
code-junkie
code-junkie - avatar
1 Answer
0
firstly you call do_twice function it takes as argument a function and two int numbers it calls the function in the argument (add in this case) with arguments the function (add) with argument x and y (take in this case are a and b) #it works like this print(do_twice(add,a,b)) #in do_twice it happens return add(add(a,b), add(a,b)) #having done add(a,b) it does #add(15,15), that is 30, so it prints 30
30th Jul 2017, 3:03 PM
Matte
Matte - avatar