Created
March 7, 2019 20:09
-
-
Save yhdesai/13c60ed46e7aa0a61f7f2143afa9c5f3 to your computer and use it in GitHub Desktop.
lcm in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python Program to find the L.C.M. of two input number | |
# define a function | |
def lcm(x, y): | |
"""This function takes two | |
integers and returns the L.C.M.""" | |
# choose the greater number | |
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 | |
# change the values of num1 and num2 for a different result | |
num1 = 54 | |
num2 = 24 | |
# uncomment the following lines to take input from the user | |
#num1 = int(input("Enter first number: ")) | |
#num2 = int(input("Enter second number: ")) | |
print("The L.C.M. of", num1,"and", num2,"is", lcm(num1, num2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment