Example HTML page

A Python program to find LCM(using functions)

In the earlier post we have seen how to find LCM using loops. In this post we will see how to find LCM using functions.


def lcm(p,q):
    if p>q:
        if((high % p==0) and (high % q==0)):
    return lcm
n1=int(input("enter value of p:"))
n2=int(input("enter value of q:"))
print("LCM of",n1,"and",n2,"is",lcm(n1,n2))


enter value of p: 12

enter value of q: 24

LCM of 12 and 24 is 24


In the above program we are defining a function definition as “def lcm” and passed parameters p and q. Now initiating a loop, in that loop we are finding the highest number which is divisible by p and q as well and this number is stored in a variable called “LCM”. If it is not possible to find that number, we incremented that number by “1”.Finally function definition is called and you will be displayed the output.


Example HTML page

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest