Articles

Program to print the first n terms in a Fibonacci series in Python

Program to print the first n terms in a Fibonacci series in Python


In the given python article, we are going to learn

  • program to print first n terms in a fibonacci series in python

Program to print the first n terms of a Fibonacci Series

The python program to print n terms of fibonacci series is as follows:

 

# Owner : TutorialsInhand Author : Devjeet Roy

number = int(input("Enter count: "))

a = 0
b = 1
sum_fib = 0
count = 1
print(a,b, end=" ")
while count <= number-2:
    sum_fib = a + b
    a = b
    b = sum_fib
    count += 1
    print(sum_fib, end=" ")

The output of the python program to print n terms of fibonacci series is as follows:

 

PS C:\Users\DEVJEET\Desktop\tutorialsInHand> python code.py                         En
Enter count: 6
0 1 1 2 3 5

Few important tips about the program

1. Here, we ask the user how  many terms of the fibonacci series he/she wants to get displayed.

2. Thereafter, we found the sum of two numbers and we have assigned the second number to first number, the sum of the two numbers to the second number and increment the counter by 1.

 

python program to print n terms of fibonacci series

 


Python Numbers Program

Would you like to see your article here on tutorialsinhand. Join Write4Us program by tutorialsinhand.com

About the Author
Devjeet Roy
Full Stack Web Developer & Data Science Enthusiast
Page Views :    Published Date : Sep 12,2021  
Please Share this page

Related Articles

Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!