2018-10-02 20:44:53 +08:00
|
|
|
# Fibonacci Sequence Using Recursion
|
|
|
|
|
|
|
|
def recur_fibo(n):
|
2018-10-12 06:41:57 +08:00
|
|
|
return n if n <= 1 else (recur_fibo(n-1) + recur_fibo(n-2))
|
2018-10-02 20:44:53 +08:00
|
|
|
|
2018-10-12 06:41:57 +08:00
|
|
|
def isPositiveInteger(limit):
|
|
|
|
return limit >= 0
|
2018-10-02 20:44:53 +08:00
|
|
|
|
2018-10-12 06:41:57 +08:00
|
|
|
def main():
|
|
|
|
limit = int(input("How many terms to include in fibonacci series: "))
|
2018-10-14 04:22:32 +08:00
|
|
|
if isPositiveInteger(limit):
|
2018-10-12 06:41:57 +08:00
|
|
|
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: ")
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|