DEV Community

Keerthana M
Keerthana M

Posted on Edited on

python task

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}')
Enter fullscreen mode Exit fullscreen mode

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}')

no = 1234

sum = 0

count=0

while no > 0:

last = no % 10

count+=1

sum += last

no //= 10

print(sum)

print(count)

no = 6754

rev=0

while no>0:

digit=no%10

rev=rev*10+digit

no=no//10

print(rev)

Top comments (0)