# 4 – Best python program to print Fibonacci sequence

## Python program to print Fibonacci sequence

Fibonacci series is a series in which numbers are in following sequences:

1, 2, 3, 5, 8, 13, 21, …

if we want to add new number in this series then we have to add last to numbers in the series.

e.g. in above series next number will be 21+13 = 34

Fn = Fn-1 + Fn-2

Following is the Python Program to generate Fibonacci series.

## Logic to print Fibonacci sequence in python

`"""Author : ITVoyagers (https://itvoyagers.in)Date :21st December 2020Description : Program to display the Fibonacci sequence up to n-th term where n is provided by the user."""# change this value for a different result#nterms = 10# uncomment to take input from the usernterms = int(input("How many terms? "))# first two termsn1 = 0n2 = 1count = 2# check if the number of terms is validif nterms <= 0:    print("Please enter a positive integer")elif nterms == 1:    print("Fibonacci sequence upto",nterms,":")    print(n1)else:    print("Fibonacci sequence upto",nterms,":")    print(n1,",",n2,end=', ')    while count < nterms:        nth = n1 + n2        print(nth,end=' , ')        # update values        n1 = n2        n2 = nth        count += 1`

Output :

How many terms? 10
Fibonacci sequence upto 10 :
0 , 1, 1 , 2 , 3 , 5 , 8 , 13 , 21 , 34 ,