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)

16th Feb 2018, 3:16 AM
I Am a Baked Potato
I Am a Baked Potato - avatar
4 ответов
+ 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
16th Feb 2018, 5:26 AM
I Am a Baked Potato
I Am a Baked Potato - avatar
0
the answer will be 24 when u carry the loop again and again.....till x>1 d increments till 24
16th Feb 2018, 5:12 AM
Jyothi Koushik
Jyothi Koushik - avatar
0
The answer wil be 25
20th Feb 2018, 12:53 PM
Hasa Srinivas
Hasa Srinivas - avatar
0
2**24=16,777,216 2**25=33,554,432 loop run for 25 times
20th Feb 2018, 2:36 PM
Santosh Kumar
Santosh Kumar - avatar