Count Digits Function
Python
Easy
3 views
Problem Description
One non-negative integer n is provided. Make function digits(n) and output digit count (for n=0 count is 1).
Input Format
One integer n.
Output Format
One integer count.
Official Solution
import sys
s=sys.stdin.read().strip()
if not s: sys.exit(0)
n=int(s)
def digits(x):
if x==0:
return 1
c=0
while x>0:
c+=1
x//=10
return c
sys.stdout.write(str(digits(n)))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!