Skip to content

Commit 0ffad22

Browse files
authored
Accept number from user and print sum of their digits
1 parent 1159a9f commit 0ffad22

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

DigitSum.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
def DigitSum(n):
2+
sum=0
3+
while(n>0):
4+
rem=n%10
5+
sum=sum+rem
6+
n=int(n/10)
7+
return sum
8+
9+
10+
11+
def main():
12+
print("\nEnter Number:")
13+
no=int(input())
14+
15+
sum=DigitSum(no)
16+
print("Sum of Digits in {} is {}\n".format(no,sum))
17+
18+
19+
if __name__=="__main__":
20+
main()

0 commit comments

Comments
 (0)