← Back to Recursion
Question 579
Sum Of One To N
Sum Of One To N
Complete sum_to(n: int) -> int so it returns 1 + 2 + ... + n by recursion. The base case is written: the sum to 0 is 0. Add the recursive case, which returns n plus the sum of all the numbers below it. 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:
10= newline. The output ends with a newline — print one after the last line.
Hints2 available
Sign in to use hintsTopics:
Recursion
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.