Last active
October 15, 2021 23:17
-
-
Save msyvr/dbb5a263c225f9bdad23bd9a6d64441d to your computer and use it in GitHub Desktop.
mit 6.0001 - recursion - compute the nth term of the Fibonacci series
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
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