AdvertisementYour brand could be hereYour brand hereOn every Darslab page · students, parents and teachersinfo@darslab.comAsk for pricesPricesinfo@darslab.com
☰ Year plan · Computing

Smaller files, smarter gates

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
000
010
100
111
Worked examples
Python
1door_open = True
2night = False
3alarm = 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 openDaylightNOT daylightLamp
0010
0100
1011
1100
The lamp circuit has an extra column for the middle result, NOT daylight. Read each row from left to right.
Python
1door_open = True
2daylight = False
3lamp = door_open and not daylight
4print(lamp)
Output
True
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.
Timer upButton pressedBell
00?
01?
10?
11?
2
In the lamp table, which row gives lamp = 1? Which door and daylight values does it have?
Garage door openDaylightNOT daylightLamp
001?
010?
101?
110?
3
What does the program print? Explain each step.
Python
1on = True
2light = True
3print(on and not light)
4
Why is it useful to write a truth table before building a circuit?