+ 1

Why doesn't this work?

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))

24th May 2019, 8:50 AM
Annette Vogt
3 Answers
+ 2
On line 5 remove the first func and the brackets surrounding the other two funcs and it will work (output: 30). By writing it like thatthe first func is expecting two parameters, instead you've put an arithmetic sum. I.E. return func(x, y) + func(x, y) You could even write it as: return func(x, y)*2 if all you are doing is adding the result of add to itself every time. EDIT: In case you wanted the function to be performed twice, you could write it like this: return func(func(x, y), func(x, y)), simply changing the plus sign you wrote in like 5 for a comma! This was a fun one, thank you for posting it lol.
24th May 2019, 9:14 AM
Rincewind
Rincewind - avatar
+ 2
Brox Brosna + in the line 5 is not accepted, because then the outer function would have an argument missing.
24th May 2019, 10:14 AM
Seb TheS
Seb TheS - avatar
+ 1
Why is + in line 5 not accepted?
24th May 2019, 8:59 AM
Annette Vogt