0

what is the output of the program mentioned in the question.

def test(func, arg): return func(func(arg)) def mult(x): return x * x print(test(mult, 2)) ***##The output is 16. how will we get that someone explain it

23rd May 2020, 4:54 AM
Ummadisetty . Lakshmi Venkata Mallikarjuna
Ummadisetty . Lakshmi Venkata Mallikarjuna - avatar
1 Answer
+ 1
So there are 3 functions lets start by mul(x) What mul x does is return the square def mul(x): return x * x <--- as seen here Now test(func, arg) What it does is that it applies same function twice. def test(func, arg): return func( func(x) ) Now what we are printing is print( test( mul, 2 ) ) so instead of func there is mul So test will return mul( mul(2) ) mul(2) will be 2 * 2 == 4 mul( 4 ) mul(4) will be 4 * 4 == 16
23rd May 2020, 5:05 AM
Utkarsh Sharma
Utkarsh Sharma - avatar