Created
September 5, 2020 09:54
-
-
Save raeq/239c063e7d05e03f3ca97cdc97776f9b to your computer and use it in GitHub Desktop.
Recursive method to find fibonacci numbers
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
def fibonacci_recursive(i: int = None) -> int: | |
""" | |
The simplest way to calculate a fibonacci number, using recursion. | |
Simple works, but not in all cases! | |
>>> fibonacci_recursive(20) | |
6765 | |
>>> # fibonacci_recursive(100) No, don't do this, it will take forever and exhaust your computer's memory | |
""" | |
if i == 0: | |
return 0 | |
if i == 1: | |
return 1 | |
return fibonacci_recursive(i - 1) + fibonacci_recursive(i - 2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment