Jan-10-2019, 06:28 PM
This is why it's incomplete:
5 % 5 evaluates to 0 (which is equivalent to False in Python).
5 % 4 == 0 evaluates to False (or 0).
0 | False evaluates to False.
To correct that, the first expression needs to be compared to 0 as well as the second:
5 % 5 | 5 % 4 == 0
Output:False
As I interpret your lambda function, you want to know if n is divisible by x or y. If you use n = 5, x = 5, and y = 4; the result is false. However, 5 is evenly divisible by 5 so the result is wrong. The interpreter is evaluating the expressions on each side of the "|" before doing the bitwise or:5 % 5 evaluates to 0 (which is equivalent to False in Python).
5 % 4 == 0 evaluates to False (or 0).
0 | False evaluates to False.
To correct that, the first expression needs to be compared to 0 as well as the second:
is_divisible = lambda n,x,y : n % x == 0 | n % y == 0