Python Program To Find Sum Of Digit Of A Number
This program calculates sum of digit of a given number by user in Python language.
In this Python program, we first read number from user and then calculate sum of its digit using while
loop. Here %
operator gives remainder and //
is used for integer division.
Python Source Code: Sum of Digit of Number
# Sum of digit of number
number = int(input("Enter number: "))
copy = number
total_sum = 0
while number:
total_sum += number % 10
number //= 10
print("Sum of digit of number %d is %d." % (copy,total_sum))
Output
Enter number: 3245 Sum of digit of number 3245 is 14.