Week 27 · 4.3–4.4 Data compression, logic gates and truth tables · 3 lessons
3
Reading a truth table
Computing 8: Topics 4.3–4.4, pp. 268–282
GoalUse a truth table to check a design and find the output for given inputs, in tables and in Python.
New words
combination · one set of values for all the inputs, such as A = 1 and B = 0condition · something that is true or false in a program
Explanation
A truth table lets a designer check all the possible inputs before building a circuit. For example, a shed alarm should sound only when the door is open AND it is night. Call the door input D and the night input N. The alarm output needs 1 only when both are 1, so this is an AND gate. A designer can also put two gates one after another. A lamp over a garage door turns on when the door is open AND it is NOT daylight. First the NOT gate reverses the daylight input. Then the AND gate combines the result with the door input. A truth table with an extra column for the middle result shows each step.
D (door open)
N (night)
Alarm
0
0
0
0
1
0
1
0
0
1
1
1
Worked examples
Python
1door_open = True2night = False3alarm = door_open and night
4print(alarm)
Output
False
The same alarm as a Python condition. With a door open and not night, the alarm is False.
Garage door open
Daylight
NOT daylight
Lamp
0
0
1
0
0
1
0
0
1
0
1
1
1
1
0
0
The lamp circuit has an extra column for the middle result, NOT daylight. Read each row from left to right.
The lamp as a Python condition. The door is open, and it is dark (daylight is False). not False is True, and True and True is True.
Class activity
Design on paper. Choose one of these invented jobs: a fish-tank light that comes on when the room is dark AND the lid is closed; a greenhouse fan that runs when it is hot OR the door is open; a night-light that comes on when it is NOT daylight. Decide the inputs and output, name the gate(s) and draw the truth table in a grid with the right number of rows. Ask a partner to read out a row and say what happens in real life. Does it make sense? If you have a computer or tablet, ask an adult to help you write the Python condition and test it with four sets of values.
Practice
1
Fill in the truth table for a school bell that rings when the timer says time is up OR the button is pressed.