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
- Get the input from user
- 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)
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