Skip to content

Commit c4a9767

Browse files
NikhilCodescclauss
authored andcommitted
Update fibonacci_sequence_recursion.py (TheAlgorithms#1287)
- Fixed minor bugs. - Minimized Codes
1 parent 6ebd899 commit c4a9767

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

maths/fibonacci_sequence_recursion.py

+7-10
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,17 @@
22

33

44
def recur_fibo(n):
5-
if n <= 1:
6-
return n
7-
else:
8-
(recur_fibo(n - 1) + recur_fibo(n - 2))
9-
10-
11-
def isPositiveInteger(limit):
12-
return limit >= 0
5+
"""
6+
>>> [recur_fibo(i) for i in range(12)]
7+
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
8+
"""
9+
return n if n <= 1 else recur_fibo(n-1) + recur_fibo(n-2)
1310

1411

1512
def main():
1613
limit = int(input("How many terms to include in fibonacci series: "))
17-
if isPositiveInteger(limit):
18-
print("The first {limit} terms of the fibonacci series are as follows:")
14+
if limit > 0:
15+
print(f"The first {limit} terms of the fibonacci series are as follows:")
1916
print([recur_fibo(n) for n in range(limit)])
2017
else:
2118
print("Please enter a positive integer: ")

0 commit comments

Comments
 (0)