Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions maths/fibonacci_sequence_recursion.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@


def recur_fibo(n):
if n <= 1:
return n
else:
(recur_fibo(n - 1) + recur_fibo(n - 2))


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


def main():
limit = int(input("How many terms to include in fibonacci series: "))
if isPositiveInteger(limit):
print("The first {limit} terms of the fibonacci series are as follows:")
if limit > 0:
print(f"The first {limit} terms of the fibonacci series are as follows:")
print([recur_fibo(n) for n in range(limit)])
else:
print("Please enter a positive integer: ")
Expand Down