Write a program in python to input a number from the user. check and display if it is a single digit number, double digit number or triple digit number.
Answers
Answer:
This is a Python Program to count the number of digits in a number.
Explanation:
The program takes the number and prints the number of digits in the number.
problem solution
1. Take the value of the integer and store in a variable.
2. Using a while loop, get each digit of the number and increment the count each time a digit is obtained.
3. Print the number of digits in the given integer.
4. Exit.
Program/source code
Here is source code of the Python Program to count the number of digits in a number. The program output is also shown below.
n=int(input("Enter number:"))
count=0
while(n>0):
count=count+1
n=n//10
print("The number of digits in the number are:",counts
Program Explanation
1. User must first enter the value of the integer and store it in a variable.
2. The while loop is used and the last digit of the number is obtained by using the modulus operator.
3. Each time a digit is obtained, the count value is incremented.
4. This loop terminates when the value of the number is 0.
5. The total count of the number of digits is printed.
Explanation:
Hope it is helpful...
please forgive me if there is any mistake...