Python Program to Display Fibonacci Sequence Using Recursion Last Updated : 19 Apr, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report We are given a task to write the Fibonacci sequence using recursion. we will take the range as input of integer and then print the Fibonacci Sequence. In this article, we will see the method of Python Program to Display Fibonacci Sequence Using Recursion. Example: Input: n = 9Output: 0 1 1 2 3 5 8 13 21Explanation: Here, we have n = 9, and we print the Fibonacci Sequence by adding one element with its subsequent element.What is the Fibonacci Sequence?The Fibonacci sequence is like a mathematical melody, where each number dances to the rhythm of the two preceding ones. It usually begins its graceful dance with the numbers 0 and 1. This sequence is not just a mere mathematical curiosity; it's like a versatile performer that appears on the stages of various mathematical and computer science domains. The Fibonacci sequence is defined by the recurrence relation: F(n) = F(n-1) + F(n-2) where ( 0 ) = 0 F(0)=0 and ( 1 ) = 1 F(1)=1. Python Program to Display Fibonacci Sequence Using RecursionBelow, are the implementation of Python Program to Display Fibonacci Sequence Using Recursion. The code defines a recursive function, fib, to generate Fibonacci series.It also contains a function print_fib to handle edge cases and initiate the Fibonacci series printing.The program checks for invalid inputs and prints appropriate messages.It initializes the series with 0 and 1 and calculates subsequent terms by summing the previous two.The driver code calls print_fib with the desired number of Fibonacci series terms, which is set to 9 in this case.Implementation Python3 # Recursive function to print the Fibonacci series def fib(n, prev1, prev2): if n < 3: return fn = prev1 + prev2 prev2 = prev1 prev1 = fn print(fn, end=" ") fib(n - 1, prev1, prev2) def print_fib(n): # When the number of terms is less than 1 if n < 1: print("Invalid number of terms") elif n == 1: print(0) elif n == 2: print("0 1") else: print("0 1", end=" ") fib(n, 1, 0) # Driver code if __name__ == "__main__": n = 9 # Function call print_fib(n) Output0 1 1 2 3 5 8 13 21 Time complexity: O(n),Auxiliary Space: O(n), Comment More infoAdvertise with us Next Article Python Program to Display Fibonacci Sequence Using Recursion K kumarwatsal43 Follow Improve Article Tags : Python Python-DSA Practice Tags : python Similar Reads R Program to Print the Fibonacci Sequence The Fibonacci sequence is a series of numbers in which each number (known as a Fibonacci number) is the sum of the two preceding ones. The sequence starts with 0 and 1, and then each subsequent number is the sum of the two previous numbers. The Fibonacci sequence has many applications in various fie 2 min read Fibonacci Sequence: Lesson for Kids Fibonacci sequence is a type series where each number is the sum of the two numbers before it. It starts from 0 and 1 usually. The Fibonacci sequence is given by 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, and so on. The numbers in the Fibonacci sequence are also called Fibonacci numbers.In this a 7 min read NumPy - Fibonacci Series using Binet Formula All of us are familiar with Fibonacci Series. Each number in the sequence is the sum of the two numbers that precede it. So, the sequence goes: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34...... In this tutorial, we will implement the same using NumPy with the aid of Binet formula. Binet Formula fn = \left [\lef 3 min read Real Life Applications of Fibonacci Sequence Fibonacci Sequence, a series where each number is the sum of the two preceding ones, finds applications in nature, mathematics, and technology. The article explores the significance and applications of the Fibonacci Sequence in various fields, including nature, mathematics, technology, finance, cryp 8 min read Python Program to Count ways to reach the n'th stair There are n stairs, a person standing at the bottom wants to reach the top. The person can climb either 1 stair or 2 stairs at a time. Count the number of ways, the person can reach the top. Consider the example shown in diagram. The value of n is 3. There are 3 ways to reach the top. The diagram is 3 min read Like