2018-10-19 20:48:28 +08:00
|
|
|
# Fibonacci Sequence Using Recursion
|
|
|
|
|
2019-10-05 13:14:13 +08:00
|
|
|
|
2018-10-19 20:48:28 +08:00
|
|
|
def recur_fibo(n):
|
2018-11-04 04:08:13 +08:00
|
|
|
if n <= 1:
|
|
|
|
return n
|
|
|
|
else:
|
2019-10-05 13:14:13 +08:00
|
|
|
(recur_fibo(n - 1) + recur_fibo(n - 2))
|
|
|
|
|
2018-11-04 04:08:13 +08:00
|
|
|
|
2018-10-19 20:48:28 +08:00
|
|
|
def isPositiveInteger(limit):
|
|
|
|
return limit >= 0
|
|
|
|
|
2019-10-05 13:14:13 +08:00
|
|
|
|
2018-10-19 20:48:28 +08:00
|
|
|
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:")
|
|
|
|
print([recur_fibo(n) for n in range(limit)])
|
|
|
|
else:
|
|
|
|
print("Please enter a positive integer: ")
|
|
|
|
|
2019-10-05 13:14:13 +08:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2018-10-19 20:48:28 +08:00
|
|
|
main()
|