Skip to content

Commit 0e93f8a

Browse files
authored
Merge pull request #64 from chandankumar1307/patch-4
Added a recursion program
2 parents 186842e + 35d51d0 commit 0e93f8a

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)