Python OOPs


Python SQLite


Examples


Others


LCM of Two Numbers using Python


Write a Python program to find LCM(Least Common Multiple) of two numbers.

n1=int(input("Enter Number 1 : "))
n2=int(input("Enter Number 2 : "))
m=max(n1,n2)
i=m
lcm=1
while True:
    if i%n1==0 and i%n2==0:
        lcm=i
        break
    i+=m
print("LCM of {} and {} is {}".format(n1,n2,lcm))
Output:
Enter Number 1 : 10
Enter Number 2 : 12
LCM of 10 and 12 is 60