Skip to content

Instantly share code, notes, and snippets.

@ianwcarlson
Last active July 29, 2018 16:59
Show Gist options
  • Save ianwcarlson/b34076c20d175ded1d62da112253d5c6 to your computer and use it in GitHub Desktop.
Save ianwcarlson/b34076c20d175ded1d62da112253d5c6 to your computer and use it in GitHub Desktop.
Implement a function recursively to get the desired Fibonacci sequence value
"""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