Answer to Question #240751 in Python for balu

Question #240751

Given an integer between 0 and 10000, write a program to print the sum of its digits.Input


The first line of input will contain an integer.Output


The first line of output should be the sum of the digits.Explanation


For example, if the given number is 25, your code should print the sum of the digits (2 + 5), which is 7.


Similarly, if the given number is 692, your code should print the sum of the digits (6 + 9 + 2), which is 17.


Similarly, if the given number is 9999, your code should print the sum of the digits (9 + 9 + 9 + 9), which is 36.

Sample Input 1

25

Sample Output 1

7

Sample Input 2

692

Sample Output 2

17

Sample Input 3

9999

Sample Output 3

36



Python 3.9


RESET




1
Expert's answer
2021-09-22T23:45:07-0400
print(sum([int(d) for d in input()]))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Viswa
29.08.22, 19:18

Good

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS