1.3.1 Truth tables

Logical Operators and Truth Tables

A truth table shows every possible combination of Boolean (True/False) inputs for a logical expression and the corresponding output. They are used to analyse the behaviour of conditions in programs and to solve logic problems.

The three logical operators are AND, OR and NOT. In Python (PLS): and, or, not.

Single-Operator Truth Tables

AND returns True only when both inputs are True.

ABA AND B
FalseFalseFalse
FalseTrueFalse
TrueFalseFalse
TrueTrueTrue

Only one row gives True. Memory aid: AND is strict — all inputs must be True.

OR returns True when at least one input is True.

ABA OR B
FalseFalseFalse
FalseTrueTrue
TrueFalseTrue
TrueTrueTrue

Only one row gives False (both False). Memory aid: OR is generous — any True input gives True.

NOT has only one input and simply inverts it.

ANOT A
FalseTrue
TrueFalse

Three-Input Truth Tables

With three inputs (A, B, C), there are 2³ = 8 possible combinations. The table is built by systematically listing all combinations — A alternates every 4 rows, B every 2 rows, C every row.

Worked example: (A AND B) OR C

ABCA AND B(A AND B) OR C
FFFFF
FFTFT
FTFFF
FTTFT
TFFFF
TFTFT
TTFTT
TTTTT

The expression is True in 5 of 8 cases. It is only False when C is False and A AND B is also False.

Applying Truth Tables to Problems

Truth tables can model real access control or decision logic. Example: a door unlocks if a PIN is correct AND a valid card is present, OR a master override is active.

pin_correct = True
card_valid = False
override = True

# (pin_correct AND card_valid) OR override
if (pin_correct and card_valid) or override:
    print("Door unlocked")
else:
    print("Access denied")
# Output: Door unlocked   (because override is True)

 Key Takeaways

  • AND: True only when both inputs are True.
  • OR: True when at least one input is True.
  • NOT: inverts its single input.
  • Two inputs → 4 rows (2²); three inputs → 8 rows (2³).
  • Build complex expressions by evaluating sub-expressions as intermediate columns.