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
1 Resposta
+ 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