Last active
April 12, 2021 02:23
-
-
Save AJ-Acevedo/afe13e4dd4b838fdb641e16d2379a3af to your computer and use it in GitHub Desktop.
Calculate the Fibonacci Sequence using Python to the nth number in the sequence 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 | |
# Fibonacci2nth | |
# version 0.2 | |
# | |
# Fibonacci Sequence using Python | |
# | |
# Calculate the Fibonacci Sequence using Python to the nth number in the | |
# sequence specified by user input on the CLI. | |
# | |
# 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 count < 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