Skip to content

Instantly share code, notes, and snippets.

@e-parkinson
Last active August 29, 2015 14:28
Show Gist options
  • Select an option

  • Save e-parkinson/00c0c30d8512320e469f to your computer and use it in GitHub Desktop.

Select an option

Save e-parkinson/00c0c30d8512320e469f to your computer and use it in GitHub Desktop.
Snippet: find the sum of natural numbers to n inclusive using recursion
i = 0
n = int(input())
running_total = 0
def make_answer(i, n, running_total):
if i > n:
print(running_total)
else:
make_answer(i+1,n,running_total+i)
make_answer(i, n, running_total)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment