In this python basic program, we will find the LCM two numbers defined by the user.
Steps to solve the program
- Take two numbers as input through the user.
- Using an if-else statement check which number is greater.
- Use While loop.
- Inside the While loop check whether both numbers divide the greater number or not.
- If yes then break the loop otherwise, add 1 to the greater number and let the loop continue.
- At the end print the output.
num1 = int(input("Enter number 1: "))
num2 = int(input("Enter number 2: "))
if num1 > num2:
greater = num1
else:
greater = num2
while(True):
if((greater % num1 == 0) and (greater % num2 == 0)):
lcm = greater
break
greater += 1
print(f"L.C.M of {num1} and {num2}: {lcm}")
Output :
Enter number 1: 150
Enter number 2: 200
L.C.M of 150 and 200: 600