2019-07-10 20:09:24 +00:00
|
|
|
"""
|
2019-10-14 18:35:51 +00:00
|
|
|
Greatest Common Divisor.
|
2019-07-10 20:09:24 +00:00
|
|
|
|
|
|
|
Wikipedia reference: https://en.wikipedia.org/wiki/Greatest_common_divisor
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2018-10-19 12:48:28 +00:00
|
|
|
def gcd(a, b):
|
2019-10-14 18:35:51 +00:00
|
|
|
"""Calculate Greatest Common Divisor (GCD)."""
|
2018-10-19 12:48:28 +00:00
|
|
|
return b if a == 0 else gcd(b % a, a)
|
|
|
|
|
2019-07-10 20:09:24 +00:00
|
|
|
|
2018-10-19 12:48:28 +00:00
|
|
|
def main():
|
2019-07-10 20:09:24 +00:00
|
|
|
"""Call GCD Function."""
|
2018-10-19 12:48:28 +00:00
|
|
|
try:
|
2019-10-05 05:14:13 +00:00
|
|
|
nums = input("Enter two Integers separated by comma (,): ").split(",")
|
2019-07-10 20:09:24 +00:00
|
|
|
num_1 = int(nums[0])
|
|
|
|
num_2 = int(nums[1])
|
2019-10-14 18:35:51 +00:00
|
|
|
print(f"gcd({num_1}, {num_2}) = {gcd(num_1, num_2)}")
|
2018-10-19 12:48:28 +00:00
|
|
|
except (IndexError, UnboundLocalError, ValueError):
|
|
|
|
print("Wrong Input")
|
2019-07-10 20:09:24 +00:00
|
|
|
|
2018-10-19 12:48:28 +00:00
|
|
|
|
2019-10-05 05:14:13 +00:00
|
|
|
if __name__ == "__main__":
|
2018-10-19 12:48:28 +00:00
|
|
|
main()
|