Last active
April 12, 2021 02:26
-
-
Save AJ-Acevedo/77eb2d6bcdca59bdc6ed332342b2e1a5 to your computer and use it in GitHub Desktop.
Calculate the Fibonacci Sequence using Python to a number specified by user input on the CLI
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
#!/usr/bin/env python | |
# Fibonacci2Num | |
# version 0.2 | |
# | |
# Fibonacci Sequence using Python | |
# | |
# Calculate the Fibonacci Sequence using Python to a number specified by user input on the CLI. | |
# The user's input string is restricted to the input fuctions's 1024 character limit. | |
# | |
# Author: AJ Acevedo - GitHub @AJ-Acevedo | |
import time | |
a = 0 | |
b = 1 | |
c = a + b | |
count = 0 | |
print("Fibonacci Sequence using Python\n") | |
print('Enter a number that you would like to calculate up to:') | |
num = int(input()) | |
print("\n") | |
# Begin logging the loop's start time. | |
startTime = time.time() | |
while c <= num: | |
print(c) | |
a = b | |
b = c | |
c = a + b | |
count += 1 | |
# End the logging of the loop's time. | |
endTime = time.time() | |
executedTime = endTime - startTime | |
print("\n") | |
print('Executed up to the nth number in the sequence: ' + str(count)) | |
print('Execution time in seconds: ' + str(executedTime)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment