Count the number of digits in a number

In this program, we will count the number of digits in a number.

Steps to solve the program
  1. Take a number in string format as input.
  2. Create a variable and assign its value equal to 0.
  3. Use for loop to iterate over each digit of the number and during iteration add 1 to the created variable.
  4. 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
				
			

find the sum of all odd numbers between 1 to n

find the first and last digits of a number

Leave a Comment