How to calculate LCM using Python3

 How to calculate LCM using Python

In this Tutorial, we will find out how to calculate the LCM using Python.

But, First we need to know that -- 

What is a LCM?


LCM (Lowest Common Multiple) is the lowest multiple that is common in 2 or more numbers. But what is a Multiple.

What is a Multiple?


A Multiple is the product of a number and other number whose range is starting from 2.

Algorithm behind finding the LCM - 


  1. Get two numbers from the user to calculate the LCM.
  2. Calculate the multiples of the two numbers.
  3. Now, compare the multiples for common ones and write down the smallest one.
Sounds Simple ? Let's get started.

n1 = int(input())
n2 = int(input())
q,r,s = [],[],[]

for i in range (1,10):
	q.append(n1*i)
	r.append(n2*i)

for a in q:
	for b in r:
		if a == b:
			s.append(a)

print (min(s))

0 Comments