+ 1
def g(x): (q,d) = (1,0) while q <= x: (q,d) = (q*10,d+1) return(d)
What does g(31415927) return
3 Respuestas
+ 5
It returns the number of digits in x
https://code.sololearn.com/cbrQ0BItZ2mj/?ref=app
+ 2
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.
Try it yourself, I added an new print statement in the code so you can see how q and d change.
https://code.sololearn.com/c5uil4c82sOi/?ref=app
0
8