Read the number whose digits to be counted. Use a while loop to get each digit of the number using a modulus // operator Increment after a digit is obtained. Continue until the value of the number is 0 Print the total count(number of digits) of the number.
Program
__author__ = 'Avinash'
input_num = int(input('Enter any number: '))
count = 0 while input_num > 0: count += 1 input_num //= 10 print("The number of digits in the given number are:", count)
Use a while loop to get each digit of the number using a modulus // operator
Increment after a digit is obtained.
Continue until the value of the number is 0
Print the total count(number of digits) of the number.
Program
__author__ = 'Avinash'
input_num = int(input('Enter any number: '))
count = 0
while input_num > 0:
count += 1
input_num //= 10
print("The number of digits in the given number are:", count)