Python Program to calculate number of digits in an integer

Number of digits in an integer in Python

Number of Digits in an integer in python program to find the length of the Integer entered by the user. The number of digits present in the Integer is the length of the Integer. Every Character or Integer or any other variable or constant either given by the user or predefined has some length. In this Python Program, we will find the length of any Integer given by the user But we need to remember some important points before writing code for finding the length of an integer :

• Length of an integer can not be calculated because integer has no iterations
• Length can be calculated only when the variable having iterations
• We can typecast Integer to string to get the length of the integer

No of iterations present in a variable gives the length of the Variable Algorithm

• Step 1:- Start
• Step 2:- Get user input
• Step 3:- Typecast the integer to string and store it in a string variable
• Step 4:- Use len() function to calculate the length of the string
• Step 5:- Print the length of variable Python Program to calculate the length of an integer

#get the user input
Integer = int(input('Enter an integer :'))
#initialize the variable
#typecast the integer to string
#store the string
String = str(Integer)
#use len() functiomn to find the length of a String
#print it
print(len(String))

Output:
Enter an integer :12345
5