Skip to content

Commit 4b82c61

Browse files
committed
Create docstring, test cases and fix a small bug
Create test cases and fix a bug where the program stop when x or y is less than or equal to 0.
1 parent d145c84 commit 4b82c61

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

lcm.py

+30
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)