← Back to challenges

Recursion: Sum

PythonHardrecursionmathnumberslanguage_fundamentals

Instructions

Write a function that finds the sum of the first n natural numbers. Make your function recursive.

Examples

sum_numbers(5) ➞ 15
# 1 + 2 + 3 + 4 + 5 = 15

sum_numbers(1) ➞ 1

sum_numbers(12) ➞ 78

Notes

  • Assume the input number is always positive.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Even Number Generator