0

need help with Functions As Object

this is the code: https://code.sololearn.com/cA79a6A20a21/# 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)) and I have been trying to understand how this works. So I tried to code this to do it triple times but I haven't understood it enough to actually make it. If you could write a code that does this triple times similar to the how first two is done if it even is possible maybe I would understand the concept of it then

11th Jan 2021, 3:00 AM
Ace
Ace - avatar
2 Antworten
+ 3
def add(x, y): return x + y def do_thrice(func, x, y): return func(func(func(x, y), func(x, y)), func(x,y)) a = 5 b = 10 print(do_thrice(add, a, b)) # 45
11th Jan 2021, 3:15 AM
Flash
0
Thank you for your help I now know how it works. I have tried other ways too For example return func(func(x,y), func(x,y))+func(x,y) does the job too as we as this one too 3*(z(x,y)) making it cleaner and clear.
11th Jan 2021, 3:57 AM
Ace
Ace - avatar