Created
August 1, 2017 13:48
-
-
Save jgarciabu/e22dfcdf293917ef524a482b62b25836 to your computer and use it in GitHub Desktop.
Ex 13 Fibonacci
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 python3 | |
# -*- coding: utf-8 -*- | |
""" | |
Write a program that asks the user how many Fibonnaci numbers to generate and | |
then generates them. Take this opportunity to think about how you can use | |
functions. Make sure to ask the user to enter the number of numbers in the | |
sequence to generate.(Hint: The Fibonnaci seqence is a sequence of numbers | |
where the next number in the sequence is the sum of the previous two numbers | |
in the sequence. The sequence looks like this: 1, 1, 2, 3, 5, 8, 13, …) | |
@author: Jeff Garcia | |
""" | |
def fibonacci(usernumber): | |
loops = 0 | |
newlist = [0,1] | |
usernumber -= 2 | |
while loops < usernumber: | |
a = (newlist[-1] + newlist[-2]) | |
newlist.append(a) | |
loops += 1 | |
return newlist | |
print(fibonacci(int(input("Generate how many Fibonacci numbers:")))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment