Python Program to Print Fibonacci Series

« Previous Program Next Program »

Print Fibonacci Series in Python

To print fibonacci series in python, you have to ask from user to enter the limit or to enter the total number of term to print the fibonacci series upto the given term.

As we know that the Fibonacci series starts from 0 and 1, and after that, every next number is the summation of the last two number. Therefore to print fibonacci series in python, just print 0 and 1 if the given limit is greater than 2 and then apply the summation of the previous two numbers to print the next number as shown in the program given below.

Python Programming Code to Print Fibonacci Series

Following python program ask from user to enter the limit upto which he/she want to print the Fibonacci series to print Fibonacci series upto to the given term:

# Python Program - Print Fibonacci Series

print("Enter 'x' for exit.");
terms = input("Upto how many terms ? ");
if terms == 'x':
    term = int(terms);
    a = 0;
    b = 1;
    count = 2;
    if term == 0:
        print("Please enter a number...exiting...");
    elif term < 0:
        print("Please enter a positive number...exiting..");
    elif term == 1:
        while count < term:
            c = a + b;
            a = b;
            b = c;
            count = count + 1;

Here is the sample run of the above python program to illustrates how to print Fibonacci series:

Below is the initial output asking to enter any number (that will be the limitation) of total fibonacci series to print:

print fibonacci series python

Now enter the term say 10 to print total 10 number in fibonacci series as shown in sample output given below:

fibonacci series python

If user supplied a negative number and press enter then here is the sample output you will see:

fibonacci series program python

Below is the same program directly written and run on python shell:

python print fibonacci series

Same Program in Other Languages

Python Online Test

« Previous Program Next Program »

© Copyright 2021. All Rights Reserved.