Dremendo Tag Line

Input a number and count the number of digits in it using while loop in Python

while Loop - Question 11

In this question, we will see how to input a number and count the number of digits in it in Python programming using while loop. To know more about while loop click on the while loop lesson.

Q11) Write a program in Python to input a number and count the number of digits in it using while loop.

Program

c=0
n=int(input('Enter any number '))

while n>0:
    c=c+1
    n=n//10

print('Total Number of Digits = %d' %(c))

Output

Enter any number 42638
Total Number of Digits = 5
video-poster