Skip to content

Instantly share code, notes, and snippets.

@kaashmonee
Created April 12, 2018 04:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaashmonee/6d9d3066aef73621bd10f088075c0947 to your computer and use it in GitHub Desktop.
Save kaashmonee/6d9d3066aef73621bd10f088075c0947 to your computer and use it in GitHub Desktop.
finding gcd with the euclidean algorithm
def gcd(a, b):
if (a == 1 or b == 1):
return 1
elif (a == 0): return b
elif (b == 0): return a
else:
# print(a, b)
return gcd(b, a % b)
def main():
to_continue = True
while (to_continue):
a = input("a: ")
b = input("b: ")
print(gcd(int(a), int(b)))
to_continue = True if (input("continue? [Y/n] ") == ("y" or "Y")) else False
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment