mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-17 14:58:10 +00:00
Update find_lcm.py (#1019)
* Update find_lcm.py Improved code quality and added comments. * Make the doctests work
This commit is contained in:
parent
f438440ac5
commit
9f8953dc0c
|
@ -4,8 +4,17 @@
|
||||||
|
|
||||||
|
|
||||||
def find_lcm(num_1, num_2):
|
def find_lcm(num_1, num_2):
|
||||||
"""Find the LCM of two numbers."""
|
"""Find the least common multiple of two numbers.
|
||||||
max_num = num_1 if num_1 > num_2 else num_2
|
>>> find_lcm(5,2)
|
||||||
|
10
|
||||||
|
>>> find_lcm(12,76)
|
||||||
|
228
|
||||||
|
"""
|
||||||
|
if num_1>=num_2:
|
||||||
|
max_num=num_1
|
||||||
|
else:
|
||||||
|
max_num=num_2
|
||||||
|
|
||||||
lcm = max_num
|
lcm = max_num
|
||||||
while True:
|
while True:
|
||||||
if ((lcm % num_1 == 0) and (lcm % num_2 == 0)):
|
if ((lcm % num_1 == 0) and (lcm % num_2 == 0)):
|
||||||
|
@ -16,8 +25,8 @@ def find_lcm(num_1, num_2):
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Use test numbers to run the find_lcm algorithm."""
|
"""Use test numbers to run the find_lcm algorithm."""
|
||||||
num_1 = 12
|
num_1 = int(input().strip())
|
||||||
num_2 = 76
|
num_2 = int(input().strip())
|
||||||
print(find_lcm(num_1, num_2))
|
print(find_lcm(num_1, num_2))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user