Friday, July 6, 2012

Generate a Fibonacci series in Python

open a python script editor and just paste the following code in your new python(.py or .pyw) file -

def fibonacciSeries ():
    previous = -1
    nextval = 1
    position =9
    for r in range(0,position):
        sum = nextval + previous
        previous = nextval
        nextval = sum
        print nextval


output is-

No comments:

Post a Comment