Display the terms of a Fibonacci series.
- Details
- Category: 11th Class computer practicals
- Published: Friday, 11 June 2021 05:53
- Written by Super User
- Hits: 1219
a=0
b=1
c=0
number=int(input('enter range for fibonacci series'))
while(number>=c):
print(c)
a=b
b=c
c=a+b
Explanation : A Fibonacci series is a special number series in which a number at any place is equal to sum of its two previous numbers in series. starting from 0 it can go up to as required.
So we have initialized three variables a,b and c. a will take value of b and b will take value of c, so as to store the values of last two numbers.c is storing the sum of last 2 numbers and printing it everytime in the while loop till number upto which series is required.
We have printed c in the starting because we have to print 0 also and series is starting from 0. So at each time in the loop logic will work and c is printed.