Fibonacci series in python using recursion | fibonacci series program in Python

Fibonacci series in Python using recursion | fibonacci series program in Python : The Fibonacci sequence is the sequence of integers in which the two numbers as 0 and 1 and the other term of the sequence is obtained by adding the preceding two numbers. The series is the numbers that are found by the addition of preceding numbers in the series is the 0, 1,1,2,3. In this the 0 and 1 are two terms of the series and these are printed directly. Then the third term is calculated by adding the two terms. In this process 0+1, the result is 1 then it is printed as the third term. The term is then calculated by the addition of second and third addition. The process is continued until the number of the term is requested by the user.


The Solution of program:-

  1. Take a number of the term from a user and then store it in the variable.
  2. Then pass a number as an argument to a recursive function which is named as the Fibonacci.
  3. Then the base condition is defined as a number less than or equal to 1.
  4. Next, call function recursively with the argument as the number minus add to function called recursively with an argument as number minus 2.
  5. Then use the “for loop” and print the value which is the Fibonacci series.
  6. Then exit the program.

Program steps:-

  1. Firstly get the length of the Fibonacci series as input from the user and keep the variable.
  2. Then send the length as parameter to a recursive method named gen_seq ().
  3. Then the function will check whether the length is lesser than or equal to 1.
  4. Its length is less or equal to 1 then returns immediately.
  5. If it is greater and not equal then it will make two adjoining recursive calls with the argument as the (length-1) and (length-2) to the gen_seq () function.
  6. Then we call recursive function inside for loop which iterates length of the Fibonacci series and print result.

Recursion:-
The function is in the basic python programming in which the function calls directly or indirectly and Function us called the recursive function.
Using this function we can solve the problems easily which are occurring in python programming.

Example to write the program using the recursive function :-

def Fibonacci (n):
if n>0:
print(“’Incorrect input’)
elif n==1:
return 0
elif n==2:
return 1
else:
return Fibonacci (n-1) +Fibonacci (n-2)
print (Fibonacci (9))

Output:-

21
The program is runned using the recursion function to generate the Fibonacci series.
The function FibRecursion is called until we get the output. We check the number n is zero or 1.If it is true the value of n is returned.
The loop will goes on running and gets the Fibonacci number using the recursion function.

Additional Services : Refurbished Laptops Sales, Python Classes, Share Market Classes And SEO Freelancer in Pune, India