Reputation: 235
How do I make the if-ladder part below shorter?
(The task is to find the smallest multiple that can be evenly divided by all numbers from 1-20. My code is inefficient, and, as I learned completely obsolete because you can do this problem with multiplying the primefactors. But anyway how to make this shorter?)
a=20
b=0
while b<1:
if (a%20==0 and
a%19==0 and
a%18==0 and
a%17==0 and
a%16==0 and
a%15==0 and
a%14==0 and
a%13==0 and
a%12==0 and
a%11==0 and
a%10==0 and
a%9==0 and
a%8==0 and
a%7==0 and
a%6==0 and
a%5==0 and
a%4==0 and
a%3==0 and
a%2==0):
b=1
else:
a=a+1
print(a)
Upvotes: 1
Views: 42