Below is a loop to find smallest common multiple of the numbers 1-20:
count=0
while not all(count % 1 == 0, count % 2 == 0,
count % 3 == 0, count % 4 == 0,
... count % 20 ==0):
count+=1
print count
It's quite tedious to type out so many conditions. This needs improvement, especially if the number is bigger than 20. However, being new to python, my knee-jerk reaction was:
while not all(count % range(1,21)==0):
...which doesn't work because python can't read minds. I've thought about putting a list inside the all(), but I'm not sure how to generate a list with variables in it.
.
Is there a shorthand to input a pattern of conditions like these, or is there a smarter way to do this that I'm missing?