CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
jackfrued

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: jackfrued/Python-100-Days
Path: blob/master/Day01-15/code/Day06/function2.py
Views: 729
1
"""
2
函数的定义和使用 - 求最大公约数和最小公倍数
3
4
Version: 0.1
5
Author: 骆昊
6
Date: 2018-03-05
7
"""
8
9
10
def gcd(x, y):
11
if x > y:
12
(x, y) = (y, x)
13
for factor in range(x, 1, -1):
14
if x % factor == 0 and y % factor == 0:
15
return factor
16
return 1
17
18
19
def lcm(x, y):
20
return x * y // gcd(x, y)
21
22
23
print(gcd(15, 27))
24
print(lcm(15, 27))
25
26