CJCoding With Joseph
15free / daySign inCreate account

Digit Sum By Recursion

Complete digit_sum(n: int) -> int so it returns the sum of the digits of a non-negative integer by recursion. The base case is written: a number below 10 is a single digit and is its own digit sum. Add the recursive case, which returns the last digit (the remainder operator % with 10) plus the digit sum of the number with that digit removed (floor division // by 10). Do NOT write a main block or any top-level test code; the tests construct the calls. Input: one integer n, no prompt, which the tests read and pass to your function before printing the value it returns.

Expected Output:

29

= newline. The output ends with a newline — print one after the last line.

Hints2 available
Topics:
RecursionOperators
📥 Auto-Input:
9875\n
This input is automatically fed to your program's stdin
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (pr, inp, def)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.