Programming Examples

Python program to accept a integer number and find its sum of digit


Write a program to accept a integer number from user and find its sum of digit.

Sample 1:

Input : 123

Output : Sum of Digit : 6

Sample 2:

Input : 1234

Output : Sum of Digit : 10

Solution

num=int(input("Enter any Number : "))
sum=0
while num>0:
    digit=num%10
    sum=sum+digit
    num=num//10
print("Sum of Digit : ",sum)
Output

Enter any Number : 123

Sum of Digit :  6

CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online Exam Quiz O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Best Website and Software Company in Allahabad Website development Company in Allahabad