Last active
August 29, 2015 14:02
-
-
Save h2rashee/2f57ce6cae8f191186e2 to your computer and use it in GitHub Desktop.
Fibonacci Numbers
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/python | |
n = input('Please specify n for the nth fibonacci number: ') | |
#Base Case | |
fiblist = [0,1] | |
#Build list up until n | |
#+1 for off-by-one adjustment | |
while len(fiblist) < n+1: | |
fiblist.append(fiblist[-1] + fiblist[-2]) | |
#Print n | |
print "The %dth fibonacci number is %d" % (n, fiblist[n]) | |
#and then the entire list leading up to it | |
print "Fibonacci list" | |
for num in fiblist: | |
print num, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment