TechieClues TechieClues
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

TechieClues
TechieClues

I specialize in creating and sharing insightful content encompassing various programming languages and technologies. My expertise extends to Python, PHP, Java, ... For more detailed information, please check out the user profile

https://www.techieclues.com/profile/techieclues

Comments (0)

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