Head add

Fibonacci Series in Python using Recursion

In this post, we are going to make a python program that will print the Fibonacci series in python using recursion.

    Fibonacci series using recursion in Python explanation

    In this post, we're going to create a Python Fibonacci series and algorithms to compute them.
    Fibonacci series is a fairly studied sequence of natural numbers. The 0th element and first element of the Fibonacci series are 0 and 1 respectively. Then, each element is the sum of the previous two numbers.

    0th element is 0.
    1st element is 1.
    2nd element is “1 + 1” is 2.
    3rd element is “1 + 2” is 3.
    4th element is “2 + 3” is 5.
    And 8, 13, 21, 34, and so on.

    General formula for this Fibonacci Series is F[n] = F[n-1] +F[n-2]

    Fibonacci Series in Python using Recursion

    In this program, we are going to make a python program that will print the Fibonacci series using recursion.
    def calc_fib(n):
        if (n <= 1):
            return n
        else:
            return calc_fib(n - 1) + calc_fib(n - 2)
    
    n = int(input())
    for i in range(n):
           print(calc_fib(i))
           
    Input: 7
    Output:
    0 1 1 2 3 5 8
    Fibonacci Series in Python using Recursion


    Fibonacci Series Program in Python in One Line

    In this program, we will take input from the user like "n" and then we will print that nth term of the Fibonacci series. We will make a python program to display the Fibonacci series.
    def calc_fib(n):
        if (n <= 1):
            return n
        else:
            return calc_fib(n - 1) + calc_fib(n - 2)
    
    n = int(input())
    print(calc_fib(n))
    
    Input: 9
    Output: 34

    Video Explanation


    About This Post

    This post is all about how can we print the Fibonacci series in the python language using Recursion. If you like this post, please share this post with your friends. If you have any other queries, let me know in the comment section.

    Related Posts:
    Calculator Program in Python using while loop
    Python Program to Find Factorial of a Number using for loop
    Menu Driven Program in Python using while loop

    Siddharth Jha
    • Hackerrank 5* • Full Stack Developer • Masters in SEO

    Related Posts

    Post a Comment