English, asked by dhivagars20, 1 year ago

What does g(31415927) return, for the following function definition?
def g(x):
(q,d) = (1,0)
while q <= x:
(q,d) = (q*10,d+1)
return(d)

Answers

Answered by Shaizakincsem
7

Answer is 25

While the 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.


Answered by Anonymous
8
While loop exits when q = 100000000 & d=8

HOPE HELPS ✌️✌️
Similar questions