Skip to content

Improve and Refactor the fibonnaciSeries.py (Recursion) #447

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Maths/FibonacciSequenceRecursion.py
Original file line number Diff line number Diff line change
@@ -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(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()
15 changes: 15 additions & 0 deletions Maths/GreaterCommonDivisor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Greater Common Divisor - https://en.wikipedia.org/wiki/Greatest_common_divisor
def gcd(a, b):
return b if a == 0 else gcd(b % a, a)

def main():
try:
nums = input("Enter two Integers separated by comma (,): ").split(',')
num1 = int(nums[0]); num2 = int(nums[1])
except (IndexError, UnboundLocalError, ValueError):
print("Wrong Input")
print(f"gcd({num1}, {num2}) = {gcd(num1, num2)}")

if __name__ == '__main__':
main()

16 changes: 0 additions & 16 deletions Maths/fibonacciSeries.py

This file was deleted.

12 changes: 0 additions & 12 deletions Maths/gcd.py

This file was deleted.