Python program to find Sum of Digits in a Number

n=int(input("Enter a number:"))
tot=0
while(n>0):
    dig=n%10
    tot=tot+dig
    n=n//10
print("The total sum of digits is:",tot)

OUTPUT:

Case 1:
Enter a number:1892
The total sum of digits is: 20
Case 2:
Enter a number:157
The total sum of digits is: 13

Sharing Is Caring

Leave a Comment