In this program, we will count the number of digits in a number.
Steps to solve the program
- Take a number in string format as input.
- Create a variable and assign its value equal to 0.
- Use for loop to iterate over each digit of the number and during iteration add 1 to the created variable.
- Print the final output.
num = '12345'
count = 0
for ele in num:
count += 1
print(f"Total digits in {num}: ",count)
Output :
Total digits in 12345: 5