QUESTION IMAGE
Question
digit count
by codechum admin
write a program that takes an integer number. use a while
loop to count the number of digits in the entered number and
print it.
sample output 1
enter a positive integer: 232512
number of digits: 6
sample output 2
enter a positive integer: 21258
number of digits: 5
sample output 3
enter a positive integer: 56767
number of digits: 5
Step1: Get user input
num = int(input("Enter a positive integer: "))
Step2: Initialize digit count
count = 0
Step3: Use while loop to count digits
while num > 0:
num = num // 10
count += 1
Step4: Print the result
print(f"Number of digits: {count}")Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
num = int(input("Enter a positive integer: "))
count = 0
while num > 0:
num = num // 10
count += 1
print(f"Number of digits: {count}")