Problem 184949 · easy · Phase 01 Prerequisites & Setup

How Many Digits?

loops · while · digits · integer division

Write digit_count(n) that returns how many digits the non-negative integer n has. Do it with arithmetic and a loop rather than converting to a string. Note that 0 has one digit.

Examples

Input:  n = 12345
Output: 5

Input:  n = 0
Output: 1

Constraints

  • 0 <= n <= 10**18

Goals

  • Peel off one digit at a time with integer division by 10
  • Handle the special case of the number 0
Starting Python…