Update fibonacci_sequence_recursion.py (#1287)

- Fixed minor bugs.
 - Minimized Codes
This commit is contained in:
Nikhil Nayak 2019-10-07 00:05:56 +05:30 committed by Christian Clauss
parent 6ebd899c01
commit c4a97677a5

View File

@ -2,20 +2,17 @@
def recur_fibo(n): def recur_fibo(n):
if n <= 1: """
return n >>> [recur_fibo(i) for i in range(12)]
else: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
(recur_fibo(n - 1) + recur_fibo(n - 2)) """
return n if n <= 1 else recur_fibo(n-1) + recur_fibo(n-2)
def isPositiveInteger(limit):
return limit >= 0
def main(): def main():
limit = int(input("How many terms to include in fibonacci series: ")) limit = int(input("How many terms to include in fibonacci series: "))
if isPositiveInteger(limit): if limit > 0:
print("The first {limit} terms of the fibonacci series are as follows:") print(f"The first {limit} terms of the fibonacci series are as follows:")
print([recur_fibo(n) for n in range(limit)]) print([recur_fibo(n) for n in range(limit)])
else: else:
print("Please enter a positive integer: ") print("Please enter a positive integer: ")