`Program to Print the Fibonacci Sequence up-to specified number of terms`

In Fibonacci sequence, each number is the sum of the two preceding ones, starting from 0 and 1.

` 1) F`_{0 }= 0 , F_{1 }= 1 and

2) F_{n }= F_{n-1 }+ F_{n-2}

_{}

Program:

`class Fibonacci:`

def __init__(self,num):`self.num=num`

def FiboSequence(self):(n1,n2,Next)=(0,1,0)for i in range(1,self.num+1):if i==1:print('{} '.format(n1),end=" ")`continue`

if i==2:print('{} '.format(n2),end=" ")`continue`

Next = n1+n2(n1,n2)=(n2,Next)print('{} '.format(Next),end=" ")if __name__=='__main__':num = int(input('Enter number of terms up-to which you want to display Fibonacci series:'))obj = Fibonacci(num)obj.FiboSequence()INPUT:

Enter number of terms up-to which you want to display Fibonacci series:13

OUTPUT:

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

## Comments

## Latikesh

20-Dec-2018 07:13:17 PMHere,is the recursive Solution to print a Fibonacci Sequence:Program:## Pankaj

20-Dec-2018 06:31:28 PM## abhijeet

20-Dec-2018 07:44:44 PM