Hi, in this tutorial, we are going to write a program which calculates the LCM of two Numbers entered by the user using Python.

## Define LCM Function

Let’s create a new function named LCM() which accepts two arguments as arguments entered by the user which calculated Lowest Common Multiple of both numbers.

*Read => Calculate and display n-th term Fibonacci Series – Python *

Let’s create a new function named LCM() which accepts two arguments as arguments entered by the user.

Let’s define a maximum variable which holds the maximum of both numbers using max() function in Python. And then assign this maximum value to the variable i.

```
maximum = max(number1, number2)
i = maximum
```

Now, what’s the **logic **behind calculating is that we need to find that lowest number which divides completely by both numbers and remainder as 0.

```
if (i % number1 == 0 and i % number2 == 0):
lcm = i
break
```

So let’s use the while loop to calculating that number until we find that number which matches our requirements and then returns lcm to the function.

```
def LCM(number1, number2):
maximum = max(number1, number2)
i = maximum
while True:
if (i % number1 == 0 and i % number2 == 0):
lcm = i
break
i += maximum
return lcm
```

### Define the Main Function

Now create the main method where we ask the user for numbers which we need to find the LCM and then pass these arguments to the function that we created above.

```
if __name__ == '__main__':
userInput1 = int(input('Enter first number: '))
userInput2 = int(input('Enter second number: '))
print('LCM of {} and {} is {}'.format( userInput1, userInput2, LCM(userInput1, userInput2)))
```

#### Source Code

```
def LCM(number1, number2):
maximum = max(number1, number2)
i = maximum
while True:
if (i % number1 == 0 and i % number2 == 0):
lcm = i
break
i += maximum
return lcm
if __name__ == '__main__':
userInput1 = int(input('Enter first number: '))
userInput2 = int(input('Enter second number: '))
print('LCM of {} and {} is {}'.format( userInput1, userInput2, LCM(userInput1, userInput2)))
```

#### Output

Hope you guys like the tutorial, feel free to drop any comments in the comment section below.

Pingback: Python Program to convert Binary Number to Decimal Number | Codez Up