mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-12-01 00:41:09 +00:00
Improve and Refactor the fibonnaciSeries.py (Recursion)
This commit is contained in:
parent
9ba96c50a2
commit
e03426b8fd
|
@ -1,16 +1,18 @@
|
||||||
# Fibonacci Sequence Using Recursion
|
# Fibonacci Sequence Using Recursion
|
||||||
|
|
||||||
def recur_fibo(n):
|
def recur_fibo(n):
|
||||||
if n <= 1:
|
return n if n <= 1 else (recur_fibo(n-1) + recur_fibo(n-2))
|
||||||
return n
|
|
||||||
|
def isPositiveInteger(limit):
|
||||||
|
return limit >= 0
|
||||||
|
|
||||||
|
def main():
|
||||||
|
limit = int(input("How many terms to include in fibonacci series: "))
|
||||||
|
if isPositiveInteger:
|
||||||
|
print(f"The first {limit} terms of the fibonacci series are as follows:")
|
||||||
|
print([recur_fibo(n) for n in range(limit)])
|
||||||
else:
|
else:
|
||||||
return(recur_fibo(n-1) + recur_fibo(n-2))
|
|
||||||
|
|
||||||
limit = int(input("How many terms to include in fibonacci series: "))
|
|
||||||
|
|
||||||
if limit <= 0:
|
|
||||||
print("Please enter a positive integer: ")
|
print("Please enter a positive integer: ")
|
||||||
else:
|
|
||||||
print(f"The first {limit} terms of the fibonacci series are as follows")
|
if __name__ == '__main__':
|
||||||
for i in range(limit):
|
main()
|
||||||
print(recur_fibo(i))
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user