Last active
August 29, 2015 14:28
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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