Fibonacci Series using Python

 

Topic: Fibonacci Series using Python.

Hey Guys, today we are going see a Python Program to print the Fibonacci Series up to n terms.

Title: Python Code for Fibonacci Series with user input. (Beginner Friendly+ Easy + Code + Output + Online Compiler)


What is this program and why we are going to use it?

This Program consists of Variables, Input Function, Loop (for loop / while loop) and Arithmetic Operator.

By using variables, we are going to store values in variables in int format. By using input function, we are going to input values from the user. For example:
n = 5
Here n is a variable where 5 is assigned to n.

Now for input function

n = int(input("Enter number of terms: "))
So, this will ask user to input number of terms.

Logic:

1. Take number of terms (n) from user.
2. Initialize two variables a = 0 and b = 1.
3. Use a loop from 0 to n.
   - Print a
   - Find next term using c = a + b
   - Update values (a = b, b = c)
4. Display the Fibonacci series.

Code:


Online Compiler (Switch to Interactive Mode before execution):



Example Output:

Input: 5
Output: 0 1 1 2 3

Applications:

1. Used in mathematical series and patterns
2. Helps in understanding loops and logic building
3. Used in algorithms and recursion concepts

Comments