Android & iPhone apps are coming soon. Log in for a plan and reminders made for you →

Coding basics · 11 of 20

Count the digits

Return how many digits a non-negative integer n has.

What you need

// divides and drops the fraction, so n // 10 removes the last digit. A while loop repeats as long as its condition is true.

n = 472
n = n // 10   # 47
while n > 0:
    n //= 10     # 4, then 0

Examples

Input n = 12345

Output 5

Input n = 0

Output 1

Zero is written with one digit.

Your code · Python

Stuck?