can anyone explain this | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 1

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 Antwort
+ 1
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 Jul 2017, 2:42 PM
Slak
Slak - avatar