Table of Contents
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 2020
Description : 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 user
nterms = int(input("How many terms? "))
# first two terms
n1 = 0
n2 = 1
count = 2
# check if the number of terms is valid
if 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 ,
We are aiming to explain all concepts of python in easiest terms as possible.

ITVoyagers
Author
PRACTICALS/PRACTICE PROGRAM IN PYTHON
CHECKOUT OTHER RELATED TOPICS
CHECKOUT OTHER QUIZZES
Quizzes on File Handling |
Easy quiz on file handling in python part 1 |
Easy quiz on file handling in python part 2 |
Quizzes on Exception Handling |
Easy quiz on Exception Handling in python part 1 |
Easy Quiz on Exception Handling in python part 2 |
Quizzes on Regular Expressions |
Easy Quiz on Regular Expression in python part 1 |
Quizzes on Python concepts coming soon… |
Python basic quiz |
New and easy python quiz basic part 1 |
New and easy python quiz (basic) part 2 |
New and easy python quiz (basic) part 3 |
Python practice quiz set |
Best Practice Quiz Set on Python Programming Part 1 |
Best Practice Quiz Set on Python Programming Part 2 |
Best Practice Quiz Set on Python Programming Part 3 |
Best Practice Quiz Set on Python Programming Part 4 |
Best Practice Quiz Set on Python Programming Part 5 |