Skip to content

Instantly share code, notes, and snippets.

@AJ-Acevedo
Last active April 12, 2021 02:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AJ-Acevedo/77eb2d6bcdca59bdc6ed332342b2e1a5 to your computer and use it in GitHub Desktop.
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
#!/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