Exam-style question
Try this first
A system should accept a person when exactly one of `has_code` and `has_pass` is True. Write a Python 3 Boolean expression using XOR for this rule. Explain the result for each possible pair of input values: True/True, True/False, False/True and False/False.
Model answer
What a good answer should say
- The expression is `has_code ^ has_pass`.
- XOR is False when both inputs are the same and True when exactly one input is True.
- Therefore, True/True gives False, True/False gives True, False/True gives True, and False/False gives False.
Explanation
Why this works
The caret operator `^` performs XOR on Boolean values in Python 3. The rule requires exactly one true input, which is the defining behaviour of XOR.
Common mistake
No common mistake is linked to this question yet.
