Program to find lcm of two numbers in python; Through this tutorial, i am going to show you how to find lcm of two numbers in python using recursion, for loop, and while loop.

LCM stands for Least common multiple. LCM is the method to find the smallest possible multiple of two or more numbers. LCM of two numbers is divisible by both the numbers. For example, LCM of 6 and 8 is 24. Hence 24 is divisible by both 6 and 8.

## Python Program to find LCM of Two Numbers

- Python Program to find LCM of Two Numbers using while loop
- Python Program to find LCM of Two Numbers using Functions
- Progarm for LCM of Two numbers in Python using Recursion

### Python Program to find LCM of Two Numbers using while loop

Use the below given steps and write a program to find lcm of two numbers in python using while loop:

- Take 2 input number from user
- Using if condition; find greater number
- Iterate while loop and find lcm of two number
- Print Lcm

# Python Program to find LCM of Two Numbers a = float(input(" Please Enter the First Value a: ")) b = float(input(" Please Enter the Second Value b: ")) if(a > b): maximum = a else: maximum = b while(True): if(maximum % a == 0 and maximum % b == 0): print("\n LCM of {0} and {1} = {2}".format(a, b, maximum)) break; maximum = maximum + 1

After executing the python program, the output will be:

Please Enter the First Value a: 25 Please Enter the Second Value b: 50 LCM of 25.0 and 50.0 = 50.0

### Python Program to find LCM of Two Numbers using Functions

Use the below given steps and write a program to find lcm of two numbers in python using the function :

- Take 2 input number from user
- Using if condition; find greater number
- Create function and Call it with numbers.
- Print Lcm

# Python Program to find LCM of Two Numbers def findlcm(a, b): if(a > b): maximum = a else: maximum = b while(True): if(maximum % a == 0 and maximum % b == 0): lcm = maximum; break; maximum = maximum + 1 return lcm num1 = float(input(" Please Enter the First Value Num1 : ")) num2 = float(input(" Please Enter the Second Value Num2 : ")) lcm = findlcm(num1, num2) print("\n LCM of {0} and {1} = {2}".format(num1, num2, lcm))

After executing the python program, the output will be:

Please Enter the First Value a: 15 Please Enter the Second Value b: 20 LCM of 15.0 and 20.0 = 60.0

### Progarm for LCM of Two numbers in Python using Recursion

Use the below given steps and write a program to find lcm of two numbers in python using recursion:

- Take 2 input number from user
- Using if condition; find greater number
- Calculate the GCD of those two values by calling findgcd function recursively
- Print Lcm

# Python Program to find LCM of Two Numbers def findgcd(a, b): if(b == 0): return a; else: return findgcd(b, a % b) num1 = float(input(" Please Enter the First Value Num1 : ")) num2 = float(input(" Please Enter the Second Value Num2 : ")) gcd = findgcd(num1, num2) print("\n GCD of {0} and {1} = {2}".format(num1, num2, gcd)) lcm = (num1 * num2) / gcd print("\n LCM of {0} and {1} = {2}".format(num1, num2, lcm))

After executing the python program, the output will be:

Please Enter the First Value a: 50 Please Enter the Second Value b: 80 LCM of 50.0 and 80.0 = 400.0

## Recommended Python Tutorials

**Recommended:-**Python Program to Count Set Bits in a Number

**Recommended:-**Python Program for BMI Calculation

**Recommended:-**Python Program to Find Out Absolute Value

**Recommended:-**Python Random Number Generator Code

**Recommended:-**Python program for Zip, Zap and Zoom game

**Recommended:-**Python Program to Swap Two Numbers

**Recommended:-**Python Program to Find n-th term of Fibonacci Series

**Recommended:-**Python Program For Calculator

**Recommended:-**Python Program to Find Strong Number

**Recommended:-**Python Program to Convert cm to Feet and Inches

**Recommended:-**How to Reverse a List in Python

**Recommended:-**Python Program to Convert Celsius to Fahrenheit

**Recommended:-**Python Program to Find Standard Deviation

**Recommended:-**Python Program to Check Perfect Number

**Recommended:-**Python Program to Display Calendar

**Recommended:-**Python Program to Print Alphabets from A to Z

**Recommended:-**Python Program to Find Roots of Quadratic Equation