Sabari M Sabari M
Updated date Mar 21, 2021
In this code snippet, we will see how to display the Fibonacci sequence using a recursive function.

Python program to display the Fibonacci sequence using a recursive function in python. Below is the code snippet,

# Fibonacci sequence in Python
input_terms = int(input("Enter terms? "))

# Recursive function for fibonacci
def recursive_fibonacci(n):
    if n <= 1:
        return n
    else:
        return recursive_fibonacci(n - 1) + recursive_fibonacci(n - 2)

# Check the input value if it is an integer or not
if input_terms <= 0:
    print("Please enter only a positive integer values")
else:
    print("Fibonacci sequence numbers are:")
    for i in range(input_terms):
        print(recursive_fibonacci(i))

Output:

Enter terms? 10
Fibonacci sequence numbers are:
0
1
1
2
3
5
8
13
21
34

ABOUT THE AUTHOR

Sabari M
Sabari M
Software Professional, India

IT professional with 14+ years of experience in Microsoft Technologies with a strong base in Microsoft .NET (C#.Net, ASP.Net MVC, ASP.NET WEB API, Webservices,...Read More

https://www.techieclues.com/profile/alagu-mano-sabari-m

Comments (0)

There are no comments. Be the first to comment!!!