Skip to content

Commit

Permalink
Create docstring, test cases and fix a small bug
Browse files Browse the repository at this point in the history
Create test cases and fix a bug where the program stop when x or y is less than or equal to 0.
  • Loading branch information
hvn2706 committed May 21, 2022
1 parent d145c84 commit 4b82c61
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lcm.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,34 @@
def lcm(x, y):
"""
Find least common multiple of 2 positive integers.
:param x: int - first integer
:param y: int - second integer
:return: int - least common multiple
>>> lcm(8, 4)
8
>>> lcm(5, 3)
15
>>> lcm(15, 9)
45
>>> lcm(124, 23)
2852
>>> lcm(3, 6)
6
>>> lcm(13, 34)
442
>>> lcm(235, 745)
35015
>>> lcm(65, 86)
5590
>>> lcm(0, 1)
-1
>>> lcm(-12, 35)
-1
"""
if x <= 0 or y <= 0:
return -1

if x > y:
greater_number = x
else:
Expand Down

0 comments on commit 4b82c61

Please sign in to comment.