I'm experienced with Python a little, however, still doesn't understand how to use all()
and any()
. I'm trying to solve a problem;
2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.
What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?
My algorithm was first like this;
tp = (1,2,3,4,5,6,7,8,9,10,
11,12,13,14,15,16,17,
18,19,20) #I used tuple so I thought process may faster than list
for x in range(100,100000,2):
for t in tp:
if x%t==0:
print(x)
However, before I run the script I realized that my algorithm is wrong because number may divisible by all of the numbers in the tuple. Then I remember all()
function, I tried to change my codes like;
if all(x%t==0):
print(x)
But I got TypeError: 'bool' object is not iterable
error. Probably I have never used all()
and any()
before, just saw some examples and I didn't understand. Could anyone explain me clearly? Then I can solve this problem.