newbie here. I've been trying to find the least common multiple of the numbers 1 thru 10. My code so far
def smallest_multiple():
a = 0
while True:
a += 1
if a%1 == 0 and a%2 == 0 and a%3 == 0 and a%4 == 0 and a%5 == 0 and a%6 == 0 and a%7 == 0 and a%8 == 0 and a%9 == 0 and a%10 == 0:
return a
print(smallest_multiple())
My result is 2520, which seems to be correct. It is the smallest number that is divisible by the numbers 1 thru 10 without remainder. But is there a way to make the 5 line shorter (not that much modulus) by iterating over them? I've tried something like this
def smallest_multiple():
a = 0
while True:
a += 1
for i in range(1, 11):
if a % i == 0:
return a
print(smallest_multiple())
But that returns just 1, not 2520. Is there a way to make
if a%1 == 0 and a%2 == 0 and a%3 == 0 and a%4 == 0 and a%5 == 0 and a%6 == 0 and a%7 == 0 and a%8 == 0 and a%9 == 0 and a%10 == 0:
shorter?