def calculate_lcm(x, y):
    if x > y:
        greater = x
    else:
        greater = y
    while (True):
        if ((greater == x == 0) and (greater == y == 0)):
            lcm = greater
            break
        greater += 1


num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
# printing the result for the users  
print("The L.C.M. of", num1, "and", num2, "is", calculate_lcm(num1, num2))

我出错了,请帮帮我.

推荐答案

# defining a function to calculate LCM  
def calculate_lcm(x, y):  
    # selecting the greater number  
    if x > y:  
        greater = x  
    else:  
        greater = y  
    while(True):  
        if((greater % x == 0) and (greater % y == 0)):  
            lcm = greater  
            break  
        greater += 1  
    return lcm    
  
# taking input from users  
num1 = int(input("Enter first number: "))  
num2 = int(input("Enter second number: "))  
# printing the result for the users  
print("The L.C.M. of", num1,"and", num2,"is", calculate_lcm(num1, num2)) 

不确定,但这可能会有所帮助,这个问题重复了很多次.

Python相关问答推荐

为什么使用SciPy中的Distance. cos函数比直接执行其Python代码更快?

预期LP_c_Short实例而不是_ctyles.PyCStructType

使用decorator 重复超载

按 struct 值对Polars列表[struct[]]排序

具有2D功能的Python十六进制图

pyautogui.locateOnScreen在Linux上的工作方式有所不同

symy.分段使用numpy数组

如何根据日期和时间将状态更新为已过期或活动?

Python库:可选地支持numpy类型,而不依赖于numpy

加速Python循环

如何从.cgi网站刮一张表到rame?

Python解析整数格式说明符的规则?

有没有一种方法可以从python的pussompy比较结果中提取文本?

无法在Docker内部运行Python的Matlab SDK模块,但本地没有问题

如何在表中添加重复的列?

当我try 在django中更新模型时,模型表单数据不可见

如何从列表框中 Select 而不出错?

在pandas数据框中计算相对体积比指标,并添加指标值作为新列

Geopandas未返回正确的缓冲区(单位:米)

跳过嵌套JSON中的级别并转换为Pandas Rame