This is my code so far.
from math import gcd
#3 digit lcm calculation
h=input("(1) 2 Digit LCM Or \n(2) 3 Digit LCM\n :")
if h == "2":
while True:
def lcm(x, y, z):
a = gcd(x, y, z)
num = x
num2 = y * z // a
LCM = num * num2 // a
return LCM
x = int(input("Number 1: "))
y = int(input("Number 2: "))
z = int(input("Number 3: "))
print("The LCM Of " + str(x) + " And " + str(y) + " And " + str(z) + " Is " + str(lcm(x, y, z)))
if h == "1":
while True:
def lcm(x, y):
a = gcd(x, y)
num = x
num2 = y
LCM = num * num2 // a
return LCM
x = int(input("Number 1: "))
y = int(input("Number 2: "))
print("The LCM Of " + str(x) + " And " + str(y) + " Is " + str(lcm(x, y)))
My problem is that the 3 digit just finds a common multiple not the lowest such a 10 , 5 , 8 makes 400 instead of a possible 40. Any help would be useful!
New Code Thanks To Prune
from math import gcd
#3 digit lcm calculation
h=input("(1) 2 Digit LCM Or \n(2) 3 Digit LCM\n :")
if h == "2":
while True:
def lcm(x, y, z):
gcd2 = gcd(y, z)
gcd3 = gcd(x, gcd2)
lcm2 = y*z // gcd2
lcm3 = x*lcm2 // gcd(x, lcm2)
return lcm3
x = int(input("Number 1: "))
y = int(input("Number 2: "))
z = int(input("Number 3: "))
print("The LCM Of " + str(x) + " And " + str(y) + " And " + str(z) + " Is " + str(lcm(x, y, z)))
One other thing, Is there another way to mark code instead of having to add 4 spaces in before each and every line. Thanks