Why in the loop is triggered or instead of and?

Good afternoon. Write a program that prints the number that divides into both numbers without a remainder.
Don't understand why the while loop works logical or operation, it should be and.
While 'the variable d will not be divisible by the first number' And 'variable d will not be divisible by the second number, THEN perform the cycle. Well then why is it "OR" is used? Although the meaning should be "And"?
``````a = int(input())
b = int(input())
d = 1
while d % a != 0 or d % b != 0:
d = d + 1
print(d)``````
June 14th 19 at 18:27
June 14th 19 at 18:29
Solution
Because the point of the algorithm is that d increases until, it will not be divisible by a and b. the while loop ends False. Thus it is necessary to construct the expression gives False when d is a divisor of a and b. That is, the inverse of the condition about which You think.
June 14th 19 at 18:31
Solution
While 'the variable d will not be divisible by the first number' And 'variable d will not be divisible by the second number, THEN perform the cycle.

No, the statement is incorrect.

The while loop runs while the condition is true. In your case either true `d % a != 0`, is either true `d % b != 0`

Ruby has until that works as you describe
June 14th 19 at 18:33
If this is not the laboratory work for the key-too much "head", then:
``````from math import gcd
lcm = a * b / gcd(a, b)``````

Oh and just for fun - implementing the same loop using iterators:
``````from itertools import count, dropwhile
lcm = next(dropwhile(lambda d: d % a != 0 or d % b != 0, count(max(a, b))))``````

PS LCM = Least Common Multiple

Find more questions by tags Python