14Sum of Digits

    Easymathloops

    Write digit_sum(n) that returns the sum of the digits of the non-negative whole number n. digit_sum(1234) is 10.

    Examples

    Example 1
    >>> digit_sum(1234)
    10
    Example 2
    >>> digit_sum(0)
    0

    Run examples checks the 2 examples above. Submit runs all 6 tests, including hidden edge cases, and marks the challenge solved.

    solution.py
    Loading Python…

    Test results show up here

    Write digit_sum in the editor, then run the examples. Use print() freely: its output is shown for each test.