Ok, the task is to find the smallest multiple that can be evenly devided by all numbers from 1-20.
My code is inefficient, and, as i learned completly obsolete because you can do this problem with multiplieing the primefactors.
But how do i make the if-part 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)
Aucun commentaire:
Enregistrer un commentaire