+ 3

What is the value of h(6,8) for the function below?def h(m,n): ans = 1 while (n > 0): (ans,n) = (ans*m,n-2) return(ans)

7th Feb 2018, 2:29 AM
kamalesh vra
kamalesh vra - avatar
2 Respostas
+ 6
n = 8, and for each iteration, n is deducted by 2, which means the loop would run 4 times, each for values of n = 8, 6, 4, 2. m = 6. The variable ans is multiplied by m for each iteration, i.e. 1*6*6*6*6 = 1296.
7th Feb 2018, 2:36 AM
Hatsy Rei
Hatsy Rei - avatar
+ 1
here we see that the loop will run until n>o ,i.e,8>0..this will happen if the loop runs for 4 times.hence for each iteration the value 6 which is obtained as (ans*m=6) will be multilplied making the answer as 6*6*6*6*1=1296
10th Feb 2018, 8:01 AM
Shankar Sharma
Shankar Sharma - avatar