mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-20 19:42:45 +08:00
increment 1
This commit is contained in:
18
maths/FibonacciSequenceRecursion.py
Normal file
18
maths/FibonacciSequenceRecursion.py
Normal file
@ -0,0 +1,18 @@
|
||||
# Fibonacci Sequence Using Recursion
|
||||
|
||||
def recur_fibo(n):
|
||||
return n if n <= 1 else (recur_fibo(n-1) + recur_fibo(n-2))
|
||||
|
||||
def isPositiveInteger(limit):
|
||||
return limit >= 0
|
||||
|
||||
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: ")
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Reference in New Issue
Block a user