Skip to content

Instantly share code, notes, and snippets.

@jgarciabu
Created August 1, 2017 13:48
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 jgarciabu/e22dfcdf293917ef524a482b62b25836 to your computer and use it in GitHub Desktop.
Save jgarciabu/e22dfcdf293917ef524a482b62b25836 to your computer and use it in GitHub Desktop.
Ex 13 Fibonacci
#!/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