Skip to content

Commit 35d51d0

Browse files
Added a recursion program
A program to print Fibonacci Series using Recursion.
1 parent 186842e commit 35d51d0

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Data Strucrures/Recursion.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Program to print the fibonacci series upto n_terms
2+
3+
# Recursive function
4+
def recursive_fibonacci(n):
5+
if n <= 1:
6+
return n
7+
else:
8+
return(recursive_fibonacci(n-1) + recursive_fibonacci(n-2))
9+
10+
n_terms = 10
11+
12+
# check if the number of terms is valid
13+
if n_terms <= 0:
14+
print("Invalid input ! Please input a positive value")
15+
else:
16+
print("Fibonacci series:")
17+
for i in range(n_terms):
18+
print(recursive_fibonacci(i))

0 commit comments

Comments
 (0)