Skip to content

Commit 00d6d46

Browse files
Merge pull request geekcomputers#1517 from hvn2706/master
Create docstring, test cases and fix a small bug
2 parents 10fefe4 + 4b82c61 commit 00d6d46

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

lcm.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,34 @@
11
def lcm(x, y):
2+
"""
3+
Find least common multiple of 2 positive integers.
4+
:param x: int - first integer
5+
:param y: int - second integer
6+
:return: int - least common multiple
7+
8+
>>> lcm(8, 4)
9+
8
10+
>>> lcm(5, 3)
11+
15
12+
>>> lcm(15, 9)
13+
45
14+
>>> lcm(124, 23)
15+
2852
16+
>>> lcm(3, 6)
17+
6
18+
>>> lcm(13, 34)
19+
442
20+
>>> lcm(235, 745)
21+
35015
22+
>>> lcm(65, 86)
23+
5590
24+
>>> lcm(0, 1)
25+
-1
26+
>>> lcm(-12, 35)
27+
-1
28+
"""
29+
if x <= 0 or y <= 0:
30+
return -1
31+
232
if x > y:
333
greater_number = x
434
else:

0 commit comments

Comments
 (0)