Question
To Count the sum of digits in a number.
Sample TestCaseExpected Output
Enter a number : 1234 Total sum of digits is 10
Answer
n=int(input("Enter a number : "))
tot=0
while n>0:
dig=n%10
tot+=dig
n//=10
print("Total sum of digits is ",tot)

No comments:
Post a Comment