0
What does f(31415927) return, for the following function definition?def f(x): d=0 while x > 1: (x,d) = (x/2,d+1) return(d)
4 Antworten
+ 2
I thought answer will be 25
the while loop will run 25 times
as 31415927 / 2**24 =1.8... which is > 1
so for last time it will go
for 2**25 , d will be incremented 24+1=25
then it becomes less than 1
condition becomes false... while loop terminates..
the no. of times x is divided by 2 & remains >1
the d will be incremented by 1
0
the answer will be 24
when u carry the loop again and again.....till x>1
d increments till 24
0
The answer wil be 25
0
2**24=16,777,216
2**25=33,554,432
loop run for 25 times