COUNT OF AN DIGIT:
no=int(input("enter a number: "))
count=0
while(no>0):
count+=1
no=no//10
print(f'count of a digit is : {count}')
OUTPUT:
enter a number: 12365
count of a digit is : 5
SUM OF DIGIT:
4 5 7 6
no = int(input("Enter any Number: ")) #1234
count_of_digits = 0
total = 0
while no > 0:
total = total + no%10 #4 4+3 7+2 9+1
print(no % 10) #Output 4 3 2 1
no = no//10 #no = 675
count_of_digits += 1
print(f'Count of Digits is {count_of_digits}')
print(f'Sum of Digits is {total}')
Top comments (0)