0
def aunt(x, y): return x + 2 def log (x,y): return x*y def do_twice(name, x, y): return name(name(x, y), log(x, y)) x = 5 y= 3 print(do_twice(aunt, x, y)) Solve this problem step by step
3 Answers
+ 1
def aunt creates a function aunt with arguments x and y and returns the value x + 2
def log creates a function log with arguments x and y and returns the product of x and y
def do_twice creates a function do_twice with arguments name(a function)and x and y and returns the value defined by name function with two arguments name of x,y and log of x,y
x is assigned the value 5 and y is assigned the value
print(do_twice (aunt,x,y)) assigns name with aunt x with x(5) and y with y(3)
name(name(x,y),log(x,y))
= aunt(aunt(5,3),log(5,3))
= aunt(7,15)
= 9
So the output of the program is 9
0
Why aunt() need y argument?
0
9
it's a cool way to call a function