Skip to content

Instantly share code, notes, and snippets.

@arsenlosenko
Created August 9, 2017 09:21
Show Gist options
  • Save arsenlosenko/2487a86d7340b0bca5c08cc005b560b1 to your computer and use it in GitHub Desktop.
Save arsenlosenko/2487a86d7340b0bca5c08cc005b560b1 to your computer and use it in GitHub Desktop.
Find GCD of two numbers in python
#!/usr/bin/env python3
def gcd():
m = int(input("Please enter first number:\n"))
n = int(input("Please enter second number:\n"))
if m > n:
num_list = range(m)
else:
num_list = range(n)
divisors_list = []
i = 1
while i < len(num_list):
if (m % num_list[i] == 0) and (n % num_list[i] == 0):
divisors_list.append(num_list[i])
i += 1
print("GCD is ", divisors_list[-1])
if __name__ == '__main__':
gcd()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment