Last active
August 29, 2015 14:23
-
-
Save jonathanpike/230f4a886cb6baccff94 to your computer and use it in GitHub Desktop.
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
# 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