Created
August 9, 2017 09:21
-
-
Save arsenlosenko/2487a86d7340b0bca5c08cc005b560b1 to your computer and use it in GitHub Desktop.
Find GCD of two numbers in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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