Creating Fibonacci Sequence in python


In mathematics, the Fibonacci numbers form a sequence, the Fibonacci sequence, in which each number is the sum of the two preceding ones.

The sequence commonly starts from 0 and 1, although some authors omit the initial terms and start the sequence from 1 and 1 or from 1 and 2. 

Starting from 0 and 1, the next few values in the sequence are:

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ...


n = int(input("Number(N) of elements in fiboSeries (N>=2):\n"))
fiboSeries = [0,1]
if n>2:
    for i in range(2, n):
        nextElement = fiboSeries[i-1] + fiboSeries[i-2]
        fiboSeries.append(nextElement)
print(fiboSeries)    

 

Comments

Popular posts from this blog

Quotation marks to wrap an element in HTML

The Basic Structure of a Full-Stack Web App

Unlocking Web Design: A Guide to Mastering CSS Layout Modes