+ 1

def g(x): (q,d) = (1,0) while q <= x: (q,d) = (q*10,d+1) return(d)

What does g(31415927) return

14th Aug 2018, 5:46 AM
kamalesh vra
kamalesh vra - avatar
3 Respostas
+ 5
It returns the number of digits in x https://code.sololearn.com/cbrQ0BItZ2mj/?ref=app
14th Aug 2018, 6:12 AM
David Ashton
David Ashton - avatar
+ 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
14th Aug 2018, 6:03 AM
Paul
Paul - avatar
0
8
14th Aug 2018, 5:51 AM
Paul
Paul - avatar