Loading...
Loading...
Loading...
A report adds the order numbers 1 to n. Write a recursive function total_to(n) that returns 1 + 2 + ... + n, read n, and print the result.
Example
Input
4
Output
10
1 + 2 + 3 + 4.
Try the problem first. Open one hint at a time.
The base case is n = 0, which gives 0.
Otherwise return n plus the total of n - 1.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor