Header Ads Widget

Write a python program to find sum of digit of a given number.

 code:-


num=int(input("Enter a number"))
di_sum=0
while num!=0:
# seperate digits from number
rem=num%10
# add digits
di_sum=di_sum+rem
num=num//10 # integer division
print("Sum of digits is: ",di_sum)

Output:-


Enter a number1234
Sum of digits is: 10



Post a Comment

2 Comments