- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# How to find the number of digits in a given number using Python?

In this program, we have to find the number of digits in an integer given by the user.

## For example

User Input: 123, Output: 3

User Input: 1987, Output: 4

## Algorithm

Step 1: Take Integer value as input value from the user

Step 2: Divide the number by 10 and convert the quotient into Integer type

Step 3: If quotient is not 0, update count of digit by 1

Step 4: If quotient is 0, stop the count

Step 5: STOP

## Example Code

x = int(input("User Input: ")) count_of_digits = 0 while x > 0: x = int(x/10) count_of_digits += 1 print("Number of Digits: ",count_of_digits)

## Output

User Input: 123 Number of Digits: 3 User Input: 1987 Number of Digits: 4

## Explanation

When we divide a number by 10 and convert the result into type **int**, the unit's place digit gets deleted. So, by dividing the result each time by 10 will give us the number of digits in the integer. Once the result becomes 0, the program will exit the loop and we will get the number of digits in the integer.

- Related Articles
- Program to find the sum of all digits of given number in Python
- Find maximum number that can be formed using digits of a given number in C++
- Find the Largest number with given number of digits and sum of digits in C++
- Write a program in Python to count the number of digits in a given number N
- Find smallest number with given number of digits and sum of digits in C++
- The sum of digits of a two-digit number is 15. The number obtained by reversing the order of digits of the given number exceeds the given number by 9. Find the given number.
- How to find the sum of digits of a number using recursion in C#?
- Number of digits in the nth number made of given four digits in C++
- Remove repeated digits in a given number using C++
- How to count digits of given number? JavaScript
- How to Find Line Number of a Given Word in text file using Python?
- Write a Golang program to find the sum of digits for a given number
- How to write Python Regular Expression find repeating digits in a number?
- C++ Program to Sum the digits of a given number
- Python Program to Find the Sum of Digits in a Number without Recursion

Advertisements