Code Library


Fibonacci series :
   
The Fibonacci sequence, also known as Fibonacci numbers, is defined as the sequence of numbers in which each number in the sequence is equal to the sum of two numbers before it. The Fibonacci Sequence is given as: Fibonacci Sequence = 0, 1, 1, 2, 3, 5, 8, 13, 21, …. Here, the third term “1” is obtained by adding the first and second term. (i.e., 0+1 = 1) Similarly, “2” is obtained by adding the second and third term (1+1 = 2) “3” is obtained by adding the third and fourth term (1+2) and so on. For example, the next term after 21 can be found by adding 13 and 21. Therefore, the next term in the sequence is 34

n = int(input("Enter range: "))
a = 0 
b = 1
if (n <= 0):
   print("Please enter a positive integer")
elif (n == 1):
   print("Fibonacci sequence upto",n,":")
   print(a)
else:
   print("Fibonacci sequence:")
   for i in range(n):
       print(a)
       c = a + b
       a = b
       b = c
Enter range: 10
Fibonacci sequence:
0
1
1
2
3
5
8
13
21
34