+ 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))
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.
+ 2
Brox Brosna + in the line 5 is not accepted, because then the outer function would have an argument missing.
+ 1
Why is + in line 5 not accepted?