Write a Python program to get the least common multiple (LCM)

Introduction

Write a Python program to get the least common multiple (LCM). I have used python 3.7 compiler for debugging purpose.

 def lcm(a, b):
   if a > b:
       z = a
   else:
       z = b
 
   while(True):
       if((z % a == 0) and (z % b == 0)):
           lcm = z
           break
       z += 1
 
   return lcm
print(lcm(10, 20))
print(lcm(15, 17))

Result

Write a Python program to get the least common multiple (LCM)
Write a Python program to get the least common multiple (LCM)

Leave a Comment