Python Program to find sum of digits

Program

num = int(input("Enter a number: "))
total = 0
while(num > 0):
    digit = num % 10
    total = total + digit
    num = num // 10
print("Sum of digits:\t", total)

Output

Enter a number: 37294
Sum of digits:	 25

Tags: