This question already has an answer here:
- Least common multiple for 3 or more numbers 19 answers
I want to ask a user to enter a number n and then create a n-element list with randomly generated numbers in [1,100], I want to find the LCM for these numbers. Lastly, I want to display the list and the LCM
import random
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
num1 = int(input("Enter the first number: "))
num2 = []
for i in range(100):2
num2.append(random.randrange(1,101,1))
print(num2)
print("The L.C.M. of", num1,"and", num2,"is", lcm(num1, num2))
I can't seem to understand what I'm doing wrong here.
Aucun commentaire:
Enregistrer un commentaire