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
0
"Answer is 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"
Answered by
0
Answer is 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.
Similar questions
Computer Science,
6 months ago
Science,
6 months ago
English,
6 months ago
Science,
1 year ago
Computer Science,
1 year ago
English,
1 year ago