Skip to content

Commit 7418ee7

Browse files
authored
Merge pull request TheAlgorithms#447 from rafagarciac/master
Improve and Refactor the fibonnaciSeries.py (Recursion)
2 parents 5d81474 + a811a0e commit 7418ee7

File tree

4 files changed

+33
-28
lines changed

4 files changed

+33
-28
lines changed

Maths/FibonacciSequenceRecursion.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Fibonacci Sequence Using Recursion
2+
3+
def recur_fibo(n):
4+
return n if n <= 1 else (recur_fibo(n-1) + recur_fibo(n-2))
5+
6+
def isPositiveInteger(limit):
7+
return limit >= 0
8+
9+
def main():
10+
limit = int(input("How many terms to include in fibonacci series: "))
11+
if isPositiveInteger(limit):
12+
print(f"The first {limit} terms of the fibonacci series are as follows:")
13+
print([recur_fibo(n) for n in range(limit)])
14+
else:
15+
print("Please enter a positive integer: ")
16+
17+
if __name__ == '__main__':
18+
main()

Maths/GreaterCommonDivisor.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Greater Common Divisor - https://en.wikipedia.org/wiki/Greatest_common_divisor
2+
def gcd(a, b):
3+
return b if a == 0 else gcd(b % a, a)
4+
5+
def main():
6+
try:
7+
nums = input("Enter two Integers separated by comma (,): ").split(',')
8+
num1 = int(nums[0]); num2 = int(nums[1])
9+
except (IndexError, UnboundLocalError, ValueError):
10+
print("Wrong Input")
11+
print(f"gcd({num1}, {num2}) = {gcd(num1, num2)}")
12+
13+
if __name__ == '__main__':
14+
main()
15+

Maths/fibonacciSeries.py

-16
This file was deleted.

Maths/gcd.py

-12
This file was deleted.

0 commit comments

Comments
 (0)