← Quiz: Boolean Algebra and Logic: all 10 questions
Quiz: Boolean Algebra and Logic · Question 4 of 10
What does this print? (code)
What does this print?
from itertools import product
f = lambda a, b: (a | b) & (1 - (a & b))
print([f(a, b) for a, b in product([0, 1], repeat=2)])
- A.[0, 1, 1, 1]
- B.[0, 1, 1, 0]
- C.[1, 0, 0, 1]
- D.[0, 0, 0, 1]
Answer & explanation
Correct answer: [0, 1, 1, 0]
(a OR b) AND NOT (a AND b) is XOR: 1 only when exactly one input is 1.
Can you get the rest right without peeking?
Take the timed Quiz: Boolean Algebra and Logic quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →