python

Fibonacci Series in Python using Recursion

In this tutorial, we are going to see how to display the Fibonacci sequence using recursion.

The Fibonacci sequence is a sequence of integers of 0, 1, 2, 3, 5, 8…

The first two terms are 0 and 1. All the other terms are obtained by adding the two previous terms. This means that the nth term is the sum of the (n-1)th and (n-2)th term.
 

 

Fibonacci Series in Python using Recursion
# Fibonacci sequence using recursion

def fibonacci(n):
    if(n <= 1):
        return n
    else:
        return (fibonacci(n-1) + fibonacci(n-2))

n = int(input("Enter a number:"))

print("Fibonacci sequence using recursion :")
for i in range(n):
    print(fibonacci(i))

This example will print the Fibonacci sequence of 10.

Enter a number: 10
Fibonacci sequence using recursion :
0
1
1
2
3
5
8
13
21
34
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

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