Count Number of Digits in a Number in Python Using While Loop

(Last Updated On: 30/03/2023)

Python Program to Count the Number of Digits Present In a Number Using While Loop

# Count the Number of Digits Present In a Number using while loop in python

num = 123456
count = 0

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

print("Number of digits: " + str(count))

Output:

Number of digits: 6

Leave a Reply

Your email address will not be published. Required fields are marked *