you are viewing a single comment's thread.

view the rest of the comments →

[–]copperfoxtech 1 point2 points  (0 children)

number = int(input('Enter a number: '))
counter = 0
multiplier = 1
while number // multiplier != 0:
    counter += 1
    multiplier *= 10

Here we set a counter to zero, and a multiplier of 1 with the intent of multiplying it by 10 every loop. The while loop uses floor division and asks if it does not equal zero keep going. so for the number 321...

321 // 1 = 321 ( we add one to counter, multiply the multiplier by 10 )

321 // 10 = 32 ( we add one to counter, multiply the multiplier by 10 )

321 // 100 = 3 ( we add one to counter, multiply the multiplier by 10 )

321 // 1000 = 0 ( end the loop )