2018-10-19 12:48:28 +00:00
|
|
|
# Fibonacci Sequence Using Recursion
|
|
|
|
|
2019-10-05 05:14:13 +00:00
|
|
|
|
2020-08-30 08:51:45 +00:00
|
|
|
def recur_fibo(n: int) -> int:
|
2019-10-06 18:35:56 +00:00
|
|
|
"""
|
|
|
|
>>> [recur_fibo(i) for i in range(12)]
|
|
|
|
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
|
|
|
|
"""
|
2019-10-18 06:13:58 +00:00
|
|
|
return n if n <= 1 else recur_fibo(n - 1) + recur_fibo(n - 2)
|
2018-10-19 12:48:28 +00:00
|
|
|
|
2019-10-05 05:14:13 +00:00
|
|
|
|
2020-08-30 08:51:45 +00:00
|
|
|
def main() -> None:
|
2018-10-19 12:48:28 +00:00
|
|
|
limit = int(input("How many terms to include in fibonacci series: "))
|
2019-10-06 18:35:56 +00:00
|
|
|
if limit > 0:
|
|
|
|
print(f"The first {limit} terms of the fibonacci series are as follows:")
|
2018-10-19 12:48:28 +00:00
|
|
|
print([recur_fibo(n) for n in range(limit)])
|
|
|
|
else:
|
|
|
|
print("Please enter a positive integer: ")
|
|
|
|
|
2019-10-05 05:14:13 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2018-10-19 12:48:28 +00:00
|
|
|
main()
|