Basic Programs

If Else Programs

While loop Programs

For loop Programs

List Programs


Python Program to Count Number of digits in given Number using While Loop


In this example shows, how to Count Number of digits in given Number using whileloop.

Steps
  1. Get the input from user
  2. Get each digit of the number and increment the count each time a digit is counted.Print the number of digits in the given integer.
Example:

Example.py
a=int(input("Enter number:"))
digits=0
while(a>0):
    digits=digits+1
    a=a//10
print("The number of digits in the number is:",digits)

Output

Enter number:857368
The number of digits in the number is: 6

Prev Next