def g(x):
(q,d) = (1,0)
while q <= x:
(q,d) = (q*10,d+1)
return(d)
Answers
Answered by
0
q is multiplied with 10 every time until it is bigger than x. d counts the number of times the q is multiplied. so in the end d = 8 and q = 100000000.
def g(x):
(q, d) = (1, 0)
while q <= x:
(q, d) = (q * 10, d + 1)
return(d)
# What does g(31415927) return
print(g(31415927)) # -> 8
print(g(1234567890)) # -> 10
Please look at this: https://code.sololearn.com/cbrQ0BItZ2mj/?ref=app#py
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
Science,
7 months ago
Science,
7 months ago
English,
1 year ago
Environmental Sciences,
1 year ago