Okay, I believe I see the issue and it appears that nilamo was right. From what I'm seeing in your tests, is_divisible() should be True when n is evenly divisible by both x and y. In which case, the logic should be:
However, equality has higher precedence than the bitwise operator per 6.16 of the Python Language Reference. So, it should be evaluated as:
I'm not sure what to make of that.
And I found my answer in 6.10 of the Python Language Reference:
def is_divisible(n, x, y): return n % x == 0 and n % y == 0Also, I noticed something odd. The bitwise statement you had was returning False for (8, 3, 4), which is the correct result according to the test you provided: Test.assert_equals(is_divisible(8,3,4),False). Going through the steps, that could only happen if the bitwise operator was evaluated prior to the equality test (==0).
Quote:8 % 3 evaluates to 2.
8 % 4 evaluates to 0.
2 | 0 evaluates to 2.
2 == 0 evaluates to False.
However, equality has higher precedence than the bitwise operator per 6.16 of the Python Language Reference. So, it should be evaluated as:
Quote:8 % 3 evaluates to 2.
8 % 4 == 0 evaluates to True.
2 | True evaluates to 3 (True).
I'm not sure what to make of that.
And I found my answer in 6.10 of the Python Language Reference:
Quote:Unlike C, all comparison operations in Python have the same priority, which is lower than that of any arithmetic, shifting or bitwise operation.