Python-100-Days/Day01-15/Day06/function2.py

27 lines
351 B
Python
Raw Normal View History

2018-03-06 00:03:44 +08:00
"""
函数的定义和使用 - 求最大公约数和最小公倍数
Version: 0.1
Author: 骆昊
Date: 2018-03-05
"""
def gcd(x, y):
if x > y:
(x, y) = (y, x)
for factor in range(x, 1, -1):
if x % factor == 0 and y % factor == 0:
return factor
return 1
def lcm(x, y):
return x * y // gcd(x, y)
print(gcd(15, 27))
print(lcm(15, 27))