Algorithm
1. Start
2. Initialize a variable count to 0
3. Accept the input number from the user
4. Repeat the following steps until the number becomes 0:
4.1. Increment the count by 1
4.2. Divide the number by 10 and update the number with the result
5. Display the value of count as the count of digits
6. End
Code Examples
#1 Code Example- Python Program Count Number of Digits in an Integer using while loop
Code -
Python Programming
num = 3452
count = 0
while num != 0:
num //= 10
count += 1
print("Number of digits: " + str(count))
Copy The Code &
Try With Live Editor
Output
#2 Code Example- Python program Using inbuilt methods
Code -
Python Programming
num = 123456
print(len(str(num)))
Copy The Code &
Try With Live Editor
Output
Demonstration
Python Programing Example to Count the Number of Digits Present In a Number-DevsEnv