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.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. def lcm(a, b):
  2. if a > b:
  3. z = a
  4. else:
  5. z = b
  6.  
  7. while(True):
  8. if((z % a == 0) and (z % b == 0)):
  9. lcm = z
  10. break
  11. z += 1
  12.  
  13. return lcm
  14. print(lcm(10, 20))
  15. print(lcm(15, 17))

Result

python language techstudy.org

     





Related Topics




Popular Posts