Elliot John Voris

Faith. Family. Technology.

Elliot John Voris - Faith. Family. Technology.

Fibonacci Sequence in Python

In case anyone ever wanted to know how to run the Fibonacci Sequence in Python, here’s how I did it:

#!/usr/bin/env python
import sys

f_seq = [ 0, 1 ]

while len(f_seq) <= int(sys.argv[1]):
    f_seq.append(f_seq[-1] + f_seq[-2])

print f_seq

Now, all you have to do is run ‘fibonacci.py 20’, and it will give you all the numbers through F20 (starting at zero).

Update: I put this up on Github, and have made a couple changes since. Check it out here!

Category: Technology

Your email address will not be published. Required fields are marked *

*