What is the value of h(231,8) for the function below?
def h(m,n):
ans = 0
while (m >= n):
(ans,m) = (ans+1,m-n)
return(ans)
Answers
Answered by
0
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.
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 multiplied making the answer as 6*6*6*6*1=1296
Similar questions