Last active
July 29, 2018 16:59
-
-
Save ianwcarlson/b34076c20d175ded1d62da112253d5c6 to your computer and use it in GitHub Desktop.
Implement a function recursively to get the desired Fibonacci sequence value
This file contains 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
"""Implement a function recursively to get the desired | |
Fibonacci sequence value. | |
Your code should have the same input/output as the | |
iterative code in the instructions.""" | |
prev1 = 0 | |
prev2 = 1 | |
count = 0 | |
def recursive(prev1, prev2, count, terminal): | |
if (count >= terminal): | |
return prev1 | |
else: | |
newValue = prev1 + prev2 | |
prev1 = prev2 | |
prev2 = newValue | |
count += 1 | |
return recursive(prev1, prev2, count, terminal) | |
def get_fib(position): | |
return recursive(0, 1, 0, position) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment