Question regarding python programming. 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)
vinithababu06:
ANSWER FR THIS
Answers
Answered by
0
8, since we are checking when 10^d <=31415927 which is when d is 7.
Since we multiply q by 10 from 1 every time till it's smaller than x and the pair the function forms is (10^d,d) d from 0 till when it is greater than x, and line shows we are checking for 10^d.
Answered by
0
Given:
g(31415927)
( q, d ) = ( 1, 0 )
Condition:
q <= x
Then,
( q , d ) = ( q * 10, d + 1 )
Solution:
The loop returns a value if q > 31415927
When d = 8,
The value of q = 100000000 and so q > 31415927
Hence, The function returns 8.
Read more on Brainly.in - https://brainly.in/question/5266216
Similar questions
Chemistry,
7 months ago
English,
7 months ago
Computer Science,
1 year ago
Social Sciences,
1 year ago