Skip to content

Instantly share code, notes, and snippets.

@jonathanpike
Last active August 29, 2015 14:23
Show Gist options
  • Save jonathanpike/230f4a886cb6baccff94 to your computer and use it in GitHub Desktop.
Save jonathanpike/230f4a886cb6baccff94 to your computer and use it in GitHub Desktop.
# from http://www.practicepython.org/exercise/2014/04/30/13-fibonacci.html
def fibonacci():
num = int(raw_input("How many numbers of the Fibonacci sequence do you want? "))
seq = [0, 1]
count = 2
if num == 0:
print "Please provide a a number greater than 0"
elif num == 1:
print "0"
elif num == 2:
print str(seq).strip('[]')
else:
while count < num:
next = seq[len(seq) - 1] + seq[len(seq) - 2]
seq.append(next)
count += 1
print str(seq).strip('[]')
fibonacci()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment