def h(x):
(m,a) = (1,0)
while m <= x:
(m,a) = (m*2,a+1)
return(a)
Answers
Answered by
1
Explanation:
The above function creates a tuple (m,a) and initialzes them with m=1,a=0.Then after that the function uses while loop upto m<=x.In the while loop on each iteration the it multiplies m with 2 and increases a by 1.In the end it returns a the second value in the tuple.
For example:
if we pass h(5) then the function return 3.
m=1 ,a=0 and x=5.
After first iteration the values will be:
m=2,a=1 and x=5.
Since m < x.
After second iteration the values:
m=4,a=2 and x=5.
Still m<x.
After third iteration.
m=8,a=3 and x=5
Now m>x the while loop will end.
The value of a will be returned that is 3.
Similar questions