# Python program to construct a Fibonacci series up to n terms

## Python program to construct a Fibonacci series up to n terms

Given a number n , write a program to construct a Fibonacci series up to n terms . So first we have to know what is Fibonacci series .

what is fibonacci series:-

In the Fibonacci series every elements are the some of two elements before it.

Fibonacci Sequence = 0, 1, 1, 2, 3, 5, 8, 13, 21, ….

Sample input

`6`

Sample output

`0 1 1 2 3 5`

## Python program to construct a Fibonacci series up to n terms

The objective of the code is to construct a Fibonacci series up to given number of terms .

Code(Python):-

pp=0 # pp=previous previous term
p=1 # p=previous term,nx=next term
print("Enter the number of term in fibonacci series")
n=int(input())
print(f"{pp} {p}",end=" ")
for i in range(2,n):
nx=pp+p;
print(nx,end=" ")
pp=p
p=nx

Output:

Enter the number of term in Fibonacci series
6
0 1 1 2 3 5

### Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-
iMocha coding Questions:-
Tech Mahindra coding questions:-
Unthinkable Solutions coding questions:-