Loading...
Loading...
Loading...
Write a recursive digit_sum(n) that adds the digits of a non-negative integer. Read n and print the sum.
Example
Input
4821
Output
15
4 + 8 + 2 + 1.
Try the problem first. Open one hint at a time.
A number below 10 is its own digit sum.
The last digit is n % 10 and the rest is n // 10.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor