Python: Fibonacci Series Using Python-DecodingDevOps

Python: Fibonacci Series Using Python-DecodingDevOps

Fibonacci series is a series in which the sum of the two numbers will give the next number in the list. This series starts with zero, followed by one and proceeds based on the rule that the sum of the two numbers will give the next number in the sequence. This Fibonacci series is generally used in the sorting algorithms in order to divide a large area into small proportions using the operations addition and subtraction. some real-life examples include shells, trees, leaves, flower petals. Fibonacci series is an unending and infinite sequence of the numbers.

Python Code For Fibonacci Series

# Python Fibonacci series Program using While loop in a certain range

Number = int(input("\nPlease Enter the Range Number: "))

i = 0

First_Value = 0

Second_Value = 1
           

while(i < Number):

           if(i <= 1):

                      Next = i

           else:

                      Next = First_Value + Second_Value

                      First_Value = Second_Value

                      Second_Value = Next
           print(Next)

           i = i + 1

STEP 1: In this step, we give an input to the user to enter the particular range in which he can generate the Fibonacci series,

STEP 2: In this step, we initialize the first and second values to zero and the first value in the Fibonacci series will always be a zero.

STEP 3: In this step, using the while loop we will check whether i is less than the number and if it is less than the number we will assign the next value with i

STEP 4: In this step, if it is greater than the number we will perform the operation which starts with adding the first and second value and assigning it to the next using the if-else loop.

STEP 5: In this step, the condition iterates until the given range is reached and will print the particular Fibonacci series in a  range given by the user.

OUTPUT:

Please Enter the Range Number: 6
0
1
1
2
3
5

 

Leave a Reply

Your email address will not be published. Required fields are marked *