Fibonacci – Python

Saturday, May 31st, 2008

Ok so if you're interviewing for a programming job you have to be able to whip out a quick Fibonacci sequence at the drop of a hat, even if inelegant. This prints the fib series for n terms: >>> def fib(n): a,b=0,1 for i in range(n): print a, a,b=b,b+a >>> fib(10) 0 1 1 2 3 ...