;

Python Program to Calculate the Sum of Digits of a Given Number


Tutorialsrack 26/04/2020 Python

In this Python program, we will learn how to calculate the sum of digits of a given number.

Here is the source code of the program to calculate the sum of digits of a given number.

Python Program to Find Sum of Digits of a Given Number
# Python Program to Find Sum of Digits of a Given Number

# Python Program to find Sum of Digits of a Number using While Loop

# Take the Input from the User
Number = int(input("Enter any Number: "))
Sum = 0

while(Number > 0):
    Reminder = Number % 10
    Sum = Sum + Reminder
    Number = Number //10

print("Sum of the digits of Given Number = %d" %Sum)
Output

Enter any Number: 5245658

Sum of the digits of Given Number = 35

 

Enter any Number: 9874563210

Sum of the digits of Given Number = 45


Related Posts



Comments

Recent Posts
Tags