BasicsChallenge 1 of 34

Sum of digits

Write digit_sum(n) that returns the sum of the decimal digits of a non-negative integer.

Examples
digit_sum(1234) → 10
digit_sum(0) → 0
Exercise

Sum of digits

3 checks
def digit_sum(n):
    ...


print(digit_sum(1234))
 
Python (loads on first run)Ctrl+Enter runs
Output
Press Run to try your code, then Check answer to grade it.