YouTip LogoYouTip

Python3 Lcm

# Python3.x Python Least Common Multiple Algorithm [![Image 3: Document Object Reference Manual](#) Python3 Examples](#) The following code implements the least common multiple algorithm: ## Example (Python 3.0+) # Filename : test.py# author by : www..com# Define function def lcm(x, y): # Get the greater number if x>y: greater = x else: greater = y while(True): if((greater % x == 0)and(greater % y == 0)): lcm = greater break greater += 1 return lcm# Get user input num1 = int(input("Enter first number: "))num2 = int(input("Enter second number: "))print("The least common multiple of", num1, "and", num2, "is", lcm(num1, num2)) Executing the above code produces the following output: Enter first number: 54Enter second number: 24The least common multiple of 54 and 24 is 216 [![Image 4: Document Object Reference Manual](#) Python3 Examples](#)
← Python3 Largest NumberPython3 Odd Even β†’