Q:

find if integer i is divisible by all elements in a list

as the title states, I want to find if integer i is divisible by all elements in a list.
I have this:
db = [3, 4, 5, 6, 7, 8]
i = 1
if all(i % d != 0 for d in db):
  i += 1

I tried using an if loop with all(), but it just skipped over that section even though the condition is met (I think). It should just add to the integer i until it is divisible by 3, 4, 5, 6, 7,and 8.
Any tips or anything I'm doing wrong?
Thanks,
Ben

A:

You checked the opposite:
If it's true for every element of db does not divide i.
You need to switch the branches of your if logic:
if all(i % d == 0 for d in db):
    print(i, "is divisible by all elements of the list")
else:
    i += 1

Alternately:
if any(i % d != 0 for d in db):
    i += 1
else:
    print(...)

Note that this appears to look for the lowest integer divisible by every integer in db.  You can do this a lot faster by more directly finding the LCM (least common multiple) of the list.  Put that into your browser's search bar.

