热门

最新

红包

立Flag

投票

同城

我的

发布
qq_52024827
qq_52024827
3 年前
trueqq_52024827

#求两个给定正整数的最大公约数和最小公倍数
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
def lcm(x,y):
if x>y:
greater = x
else:
greater = y
while(True):
if(greater % x ==0) and (greater % y == 0):
lcm = greater
return lcm(x, y)
num1 = int(input("输入第一个数字:"))
num2 = int(input("输入第二个数字:"))
print("最大公约数为",hcf(num1,num2),"最小公倍数为",lcm(num1,num2))


请问有大神可以看出有什么问题吗?我输入数字之后得不出结论是怎么回事呀!!小白在线求助

CSDN App 扫码分享
分享
评论
点赞
打赏
  • 复制链接
  • 举报
下一条:
秃子我来啦
立即登录