Image of the glider from the Game of Life by John Conway
Skip to content

Python Fibonacci Sequence

So, in case you were wondering, Pthree stands for Perl, Python and PHP. I know, I know. I haven't posted hardly anything at all. So I make a feeble attempt at starting now.

Everything that I have been doing at work is supposed to be written in Python, but instead, I have been writing everything in Bash. Well, tonight, I turn over a new leaf. It's time to convert many of Bash scripts into Python.

Problem.

I don't know Python.

So, I have decided to start getting serious. I have literally jumped leaps and bounds these past few months learning Bash, and while I am far from perfect, I think I should begin applying that energy to Python. So, here we go.

First, I went to http://doc.python.org, and began reading. It wasn't long, but I stumbled upon writing a Fibonacci sequence in Python. I thought, sure, why not?

1
2
3
4
a,b=0,1
while b < 10:
        print b
        a, b = b, a+b

Not bad. Only 4 simple lines, and already, I feel like I am getting the hang of the language. The only problem, is, if I don't have any exercises to run through, then I won't have any motivation to learn the language, and if I spend time learning the language, then by the time it will be time to convert everything over, the window will have passed, and I will feel like I wasted time.

Anyway, I am enjoying myself, and I guess that is what is most important. Maybe in the next post, I'll post a solution in Python to the traveling salesman problem. 🙂

{ 3 } Comments