### Python Program to Print the Fibonacci Sequence ( without Recursion)

`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)  F0 = 0  , F1 = 1  and`
`          2)  Fn = Fn-1 + Fn-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

#### More Articles of abhijeet singh:

Name Views Likes
Python program to find diameter of a binary tree 820 16
Python program to find sum of all leaf nodes of binary tree 357 18
Python program to find height of a tree using recursion 385 16
Python program to find sum of all nodes in a binary tree 385 15
Python program to check whether a given binary tree is complete or not using recursion 322 18
Python program to check whether a binary tree is a full binary tree or not using recursion 428 30
Python program to convert a given binary search tree to doubly linked list 356 20
Python program to find K%u2019th largest element in binary search tree 342 25
Python program to find lowest Common Ancestor in a binary search tree 368 21
Python program to find k-th smallest element in binary search tree 324 17
Python program to find the node having maximum value in a binary search tree 327 19
Python program to find the node having minimum value in a binary search tree 385 18
Python program to construct binary search tree from given preorder traversal 377 18
Python Program to Implement Queue using two Stacks 404 19
Python Program to count and display occurence of a given Character and lines not starting with given Character 350 18
Python Program to find number of alphabets and number of lines in a file 303 17
Python Program to write numbers 1 to 100 in a file 327 17
Python Program to find number of words in the file 299 12
Python Program to create a file,find size of a file and copy content of one file in another 335 22
Python Program to create and delete a File 350 21
Python Program to demonstrate Monkey Patching 317 11
Python Program to find Sum of list (with string types) 344 21
Python program to create a list of tuples from given list having number and its cube in each tuple 435 18
Python Program to find missing number in a given integer array of 1 to 100 477 23
Python Program to perform files compression to tar file and extract a tar file 298 14
Python Program to demonstrate Various list Functions 444 15
Python GUI Registration Form Using Tkinter 916 25
Python Automated tool to convert Plain Text to Formatted text using Pygments 413 21
Python Program to Generate random numbers 327 20
Python Program to Swap two strings 376 20
Python Program to Perform Set Operations 354 22
Python Program to Find the Transpose of a Given Matrix 385 18
Python Program to Perform Addition,Subtraction and Multiplication of two Matrices 2192 23
Python Program to Calculate Permutation(nPr) and Combination(nCr) 712 23
Python Program to Find the Factorial of a Given Number 297 13
Python Program to Print the Fibonacci Sequence ( without Recursion) 368 26
Python Program to Calculate the Perimeter of a Square 373 28

• ###### Latikesh
20-Dec-2018 07:13:17 PM
Here,is the recursive Solution to print a Fibonacci Sequence:

Program:
`def Fibonacci(number):`
`	if(number <= 1):`
`		return number`
`	else:`
`		return(Fibonacci(number-1) + Fibonacci(number-2))`

`def main():`
`	`
`	n = int(input("Enter number of terms up-to which you want to display Fibonacci series:"))`
`	for i in range(n):`
`		print (Fibonacci(i))`
`		`
`if __name__=='__main__': `
main()
• ###### Pankaj
20-Dec-2018 06:31:28 PM
Good Article Abhijeet.
• ###### abhijeet
20-Dec-2018 07:44:44 PM
Thankyou sir