Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
5.1k views
in Python Functions by (54.8k points)
closed by

Write a Python code to find the L.C.M. of two numbers?

1 Answer

+1 vote
by (49.1k points)
selected by
 
Best answer

Method I using functions:

def lcm (x, y):

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

num 1 = int (input(“Enter first number : “))

num 2 = int (input(“Enter second number : “))

print (“The L.C.M of” , numl, “and” , num, “is” , lcm(num1, num2))

Method II

(without using functions)

a = int (input (“Enter the first number :”))

b = int (input (“Enter the second number :”))

if a > b:

mini = a

else:

min 1 = b

while(1):

if (min 1 % a = = 0 and mini 1 % b = = 0):

print (“LCM is:” , mini)

break

mini = min 1 + 1

Output:

Enter the first number: 15

Enter the second number: 20

LCM is: 60

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

...