Created
May 13, 2017 08:14
-
-
Save odanga94/46ada373732829517f71ec721781c849 to your computer and use it in GitHub Desktop.
Fiboncacci/Exercise13.py
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(): # where n is the nth number of the Fibonacci sequence the function will generate | |
fib_list = [] | |
fib_1 = 1 # by definition the first two numbers in the Fibonacci sequence are both 1 | |
n = int(input("How many numbers in the Fibonacci sequence would you like to generate? ")) | |
if n == 1 or n ==2: | |
for i in range(n): | |
fib_list.append(fib_1) | |
else: | |
for i in range(2): | |
fib_list.append(fib_1) | |
count = 2 | |
while count < n: | |
fib_current = (fib_list[count - 1]) + (fib_list[count -2]) | |
fib_list.append(fib_current) | |
count += 1 | |
print(fib_list) | |
fibonacci() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment