Skip to content

Instantly share code, notes, and snippets.

@h2rashee
Last active August 29, 2015 14:02
Show Gist options
  • Save h2rashee/2f57ce6cae8f191186e2 to your computer and use it in GitHub Desktop.
Save h2rashee/2f57ce6cae8f191186e2 to your computer and use it in GitHub Desktop.
Fibonacci Numbers
#!/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