Python Practice › Function Programs › Program 15
LCM function
Write a Python function to find the LCM of two numbers.
Input
12, 20
Output
60
Approach
- LCM = a × b // HCF.
Solution
def hcf(a, b): while b: a, b = b, a % b return a def lcm(a, b): return a * b // hcf(a, b) print(lcm(12, 20))Output
60
Learn the concept
New to this topic? Read the lesson, then come back.