Count Digits with while
Completed
Read a non-negative integer and print how many digits it has, using a while loop (no strings).
Input
One integer ≥ 0.
Output
The number of digits.
Example
Input
12345
Output
5
Editor
Python
Hints
Each n //= 10 removes one digit.
0 has one digit.
Solution explanation
while repeats as long as its condition is true — useful when you don't know the number of steps in advance.
Show solution
n = int(input())
count = 1
while n >= 10:
n //= 10
count += 1
print(count)