-
-
Save sujyrokimora/771cd648b4f965d9eb43a733b6eab63c to your computer and use it in GitHub Desktop.
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
| import time | |
| def fibonacci(n): | |
| """ | |
| Calculates fibonnaci sequence numbers recursively | |
| """ | |
| if n == 0: | |
| return 0 | |
| elif n == 1: | |
| return 1 | |
| else: | |
| return fibonacci(n - 1) + fibonacci(n - 2) | |
| def constant(n): | |
| """ | |
| Calculates fibonacci constant | |
| """ | |
| s = 1 | |
| c = 0 | |
| while s < n: | |
| c = c + (1 / fibonacci(s)) | |
| s += 1 | |
| print(s, " Im Still Alive! just thinking...") | |
| return c | |
| def main(): | |
| n = input("How many numbers?\n") | |
| startTime = time.time() | |
| print( constant( int(n) ) ) | |
| endTime = time.time() | |
| print("Done in only ", endTime-startTime, " seconds!") | |
| if __name__ == "__main__": | |
| main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment