运行效果截图:
def hcf(x, y):
"""该函数返回两个数的最大公约数"""
# 获取最小值
if x > y:
smaller = y
else:
smaller = x
for i in range(1, smaller + 1):
if ((x % i == 0) and (y % i == 0)):
hcf = i
return hcf
# 用户输入两个数字
num1 = int(input("Input the first number: "))
num2 = int(input("Input the second number: "))
print("The GCD of", num1, "and", num2, "is", hcf(num1, num2))