Python Program - Count the Number of Digits Present In a Number

You can count the number of digits present in a number using the following Python program:

refer to:‮editfigi‬a.com
num = int(input("Enter a number: "))

count = 0

while num > 0:
    num = num // 10
    count += 1

print("Number of digits:", count)

In this program, we first take an integer input from the user. We then initialize a variable count to zero, which will store the count of digits in the number.

We then use a while loop to keep dividing the number by 10 until it becomes zero. In each iteration, we increment the count variable by 1.

Finally, we print the value of the count variable, which gives us the number of digits present in the input number.