Python program to print lcm of two numbers. The LCM numbers will be printed using the Python programming language. The simplest option for beginners is to use the Python language to solve multiple problems. The “smallest non-zero common number” that is a multiple of both numbers is the “least common multiple of two numbers”.
def compute_lcm(x, y): if x > y: bigger = x else: bigger = y while(True): if((bigger % x == 0) and (bigger % y == 0)): lcm = bigger break bigger += 1 return lcm a = 30 b = 20 print("Result is", compute_lcm(a, b))
Result is 60