Fibonacci Series in Python Using While Loop

Fibonacci series in python using while loop. Python code to calculate the Fibonacci sequence. For beginners, this program will print the fibonacci series number in the Python programming language. The Fibonacci sequence program is the most important program for anyone learning a new programming language.

a = int(input("How many numbers do you want? ")) 
n1 = 0 
n2 = 1 
num = 2 
if a <= 0: 
print("enter the number") 
elif a == 1: 
print("Fibonacci series") 
print(n1) 
else: 
print("Fibonacci series") 
print(n1,",",n2,end=', ') 
while num < a: 
nth = n1 + n2 
print(nth,end=' , ') 
n1 = n2 
n2 = nth 
num += 1

 

Output:

How many numbers do you want?

5

Fibonacci sequence: 0 , 1, 1 , 2 , 3

Fibonacci Series in Python

The Fibonacci Series is a numerical pattern in which each number is the sum of the previous two consecutive numbers. The first two integers are 0 and 1. 0+1=1 is the third number in the series. The fourth number is the sum of the second and third numbers, which is 1+1=2 and so on. 

Fibonacci levels are utilised as guidelines to identify potential locations for trade development. Prior to acting on the Fibonacci level, the price should confirm. Traders don’t know which level will be crucial ahead of time, so they must wait and watch which level the price respects before entering a trade.

If Else Statement in Python

If not, then A Python statement determines whether or not an expression is true or false. The “if” statement is executed if a condition is met. Otherwise, the “otherwise” phrase takes effect. This is when conditional statements come into play. Conditional statements allow you to more efficiently manage the flow of your program.

While Loop in Python

Python While Loop is used to run a series of statements until a certain condition is met. When the condition is met, the line immediately after the loop in the program is performed. While loop is an example of endless iteration.