C C++ JAVA PYTHON SQL HTML CSS DSA Robotics AWS CODING INTERVIEW PREPARATION

Made with  & Code

# Fibonacci series program in Python

Written By -

## Python program for Fibonacci series(Using for loop)

Fibonacci series is the program based on Fibonacci spiral. This series is formed by addition of 2 previous numbers to coin the third term. Initiated by two numbers 0 and 1.

In this program we are going to generate a Fibonacci series using python.

For example:
Series contain
First term =0
Second term=1
Third term= 0+1=1
Fourth term= 1+1=2
.
.
So on.

Algorithm:

1. Initialise the first 2 numbers as 0 and 1.
2. Define a for loop for the number of terms you want in the series.
3. Print the function.
4. Exit.

Code:

``````#Program to print Fibonacci series
n= int(input("enter the number of elements you want in series:"))
c=[]
c.append(0)
c.append(1)
a=0
b=1
d=0

for i in range( 1, n-1):
d=a+b
c.append(d)
a=b
b=d

for i in c:
print(i)``````

Output:

``````enter the number of elements you want in series: 4
0
1
1
2``````

Related Posts:

Online Compilers