Python Program to Find Sum of Digits of a Number

Problem: Write a python program to find the sum of digits of given number.

This program accept a number from the user and calculates the total sum of digits of given number using while loop and modulo division operators.

Python program to find sum of digits of given number

num=int(input("Enter any number:"))
sum1=0
while(num>0):
    digit=num%10
    sum1=sum1+digit
    num=int(num/10)
print("The sum of digits of given number is",sum1)

Output:

Enter any number:1234
The sum of digits of given number is 10