最小公倍数

计算两个数的最小公倍数

 1 def lcm(x, y):
 2     '''该函数返回两个数的最小公倍数'''
 3     if not(x > 0 and y > 0):
 4         print("Invalid numbers!")
 5     # 获取较大的数
 6     if x > y:
 7         bigger = x
 8     else:
 9         bigger = y
10     while True:
11         if (bigger % x == 0) and (bigger % y == 0):
12             lcm = bigger
13         else:
14             bigger += 1
15     return lcm
16 
17 
18 num1 = int(input('请输入第一个数字:'))
19 num2 = int(input('请输入第二个数字:'))
20 print(num1, '', num2, '的最小公倍数是:', lcm(num1, num2))
原文地址:https://www.cnblogs.com/gzj137070928/p/13816338.html