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

31st Jul 2016, 12:06 PM
Rupam Das
Rupam Das - avatar
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
1st Aug 2016, 6:20 PM
Lunu'anaki
Lunu'anaki - avatar
0
Why aunt() need y argument?
31st Jul 2016, 12:49 PM
TheMatten
TheMatten - avatar
0
9 it's a cool way to call a function
31st Jul 2016, 4:09 PM
王ć»ș霖
王ć»ș霖 - avatar