Skip to content

Instantly share code, notes, and snippets.

@msyvr
Last active October 15, 2021 23:17
Show Gist options
  • Save msyvr/dbb5a263c225f9bdad23bd9a6d64441d to your computer and use it in GitHub Desktop.
Save msyvr/dbb5a263c225f9bdad23bd9a6d64441d to your computer and use it in GitHub Desktop.
mit 6.0001 - recursion - compute the nth term of the Fibonacci series
def fibo(n):
'''return element 'i' of the Fibonacci series (its initial element is element '1')'''
if n == 0 or n == 1:
return 1
elif n > 1:
return fibo(n-2) + fibo(n-1)
if __name__ == "__main__":
i = int(input('Which element to compute in the Fibonacci sequence?: '))
print(f'Element {i} in the Fibonacci sequence: {fibo(i-1)}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment