Tutorpip← About this lessonOpen the sheet →Download PDF
Ages 10+ · Coding · Logic and puzzles
Truth tables, simply
AND lamp: both on• off, off: dark• off, on: dark• on, off: dark• on, on: litOR lamp: either on• off, off: dark• off, on: lit• on, off: lit• on, on: lit
Two lamps, four rows each.
The big ideaA truth table lists every way the inputs can be, and the answer for each.

How it works

A truth table lists every way the inputs can be, and the answer for each one.

Each switch is off or on, so each extra switch doubles the number of rows.

An AND lamp lights only when both switches are on. An OR lamp lights when either one is on.

Checking every row is how you catch a bug that likes to hide.

Rows in a truth table0510152021 switch42 switches83 switches164 switchesrows
Each extra switch doubles the rows.
Try twosettingsThey look fineAda triesanotherA bug shows up
How Leo's bug showed up.

Example 1: Two switches

  1. Each switch is off or on, so two switches make two times two.
  2. 2 * 2 = 4 rows.
  3. The rows are off and off, off and on, on and off, and on and on.

Example 2: The AND lamp

  1. An AND lamp needs both switches on.
  2. Only the last row lights it: on and on.
  3. The other three rows stay dark.

Example 3: The OR lamp

  1. An OR lamp lights when either switch is on.
  2. It is dark in the first row only: off and off.
  3. Every other row lights it.

Example 4: Three switches

  1. A third switch doubles the rows again.
  2. 2 * 2 * 2 = 8 rows.
  3. A table never skips a case, however big it gets.

Example 5: A bug that hid

  1. Leo tried off and off, and on and on, and the lamp looked right.
  2. Ada flipped only the first switch, and the lamp lit when it should stay dark.
  3. Two rows failed, because his switches sat side by side.
  4. Checking every row found the bug, and Leo rewired them in a row.

Words to know

switch
Off or on. It is an input.
row
One way the switches can be set.
truth table
A list of every row and the answer for each.
AND
Both must be on.
OR
Either one is enough.

Watch out

Try it

  1. How many rows does a table for four switches have?
  2. Only switch two is on. Does an AND lamp light?
  3. Only switch one is on. Does an OR lamp light?
  4. Both switches are off. Does either lamp light?
  5. True or false: three switches have the same rows as two switches.
Answers: 1. 16 · 2. No · 3. Yes · 4. No · 5. False
Try at homeWith a grown-up, pick a rule with two parts, like: I can watch a show if my homework is done and my chores are done. Draw all four rows of the table on paper, and mark each row yes or no.
For grown-upsPick a rule with two parts, like: I can watch a show if my homework is done and my chores are done. Draw all four rows of the table on paper together and mark each row yes or no.
Open these notes on screenScan the code, or go to tutorpip.com.