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
Post a Comment
Write something to CodeWithAbdur!