Answers for "math.lcm python"

2

lcm math python library

from math import gcd
def lcm(a,b):
  return a*b/(gcd(a,b))
print(lcm(12,70))
//output: 420
Posted by: Guest on June-07-2020
1

lcm python

# Python program to find the L.C.M. of two input number

# This function computes GCD 
def compute_gcd(x, y):

   while(y):
       x, y = y, x % y
   return x

# This function computes LCM
def compute_lcm(x, y):
   lcm = (x*y)//compute_gcd(x,y)
   return lcm

num1 = 54
num2 = 24 

print("The L.C.M. is", compute_lcm(num1, num2))
Posted by: Guest on December-25-2020
0

phython lcm

def lcm(x, y):

   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

x = int(input("enter number 1: "))
y = int(input("enter number 2: "))

print("L.C.M of",x,"and",y,"=",(lcm(x,y)))
Posted by: Guest on November-18-2021

Python Answers by Framework

Browse Popular Code Answers by Language