GoalUse a truth table, explain how rules differ from machine learning, and describe how a sensor, a decision and an action fit together.
New words
truth table · a table that lists every combination of inputs and the output for eachmachine learning · a way for a computer to find patterns in many examples and use them to decide new casesaugmented reality · a real view with computer-generated extras added on topautonomous · working without a person controlling each step
Explanation
A logic gate turns inputs of 0 or 1 into an output of 0 or 1. NOT flips its input, AND gives 1 only when both inputs are 1, and OR gives 1 when at least one input is 1. A truth table lists every combination, and with two inputs there are four rows. A computer that uses preprogrammed rules does only what its programmer wrote. A machine learning system finds the pattern itself from many examples. It can still be wrong or unfair if its examples are poor or one-sided, so people must check it. Augmented reality adds computer-generated labels or models to a real view, and they are not proof that something is really there. An autonomous system senses the world, decides with a rule and acts, without a person for each step.
sensor readsthen→program decidesthen→output acts
Worked examples
A: cover off
B: lifeguard
NOT B
A AND NOT B
0
0
1
0
0
1
0
0
1
0
1
1
1
1
0
0
A pool alarm sounds when the cover is off and no lifeguard is present. The rule is A AND NOT B, where A is cover off and B is lifeguard present. The NOT column is the middle step. Only one row gives 1: the cover is off and nobody is there.
Message has WIN?
Sender known?
Label
yes
no
spam
yes
yes
not spam
no
no
not spam
no
yes
not spam
yes
no
spam
yes
yes
not spam
Learning a pattern from examples. Look for what is true of every spam message and of no other. Spam appears only when the message has the word WIN and the sender is unknown. A new message with WIN from an unknown sender is therefore spam. If the examples had never shown a known sender with WIN, the system could wrongly block mail from friends.
Sense, decide, act. A rain sensor gives a number from 0 to 10, and the program closes the window when it is 6 or more, half closes it for 3 to 5, and leaves it open below 3. The sensor reading is the input, the if / elif chain is the decision, and the printed message stands for the action. With 3 typed, 3 >= 6 is false and 3 >= 3 is true.
Class activity
Teach-back (no computer). Write eight topics of the year on cards: pseudocode, choices in Python, testing and validation, micro:bit radio, models and what-if, networks and safety, binary and ASCII, gates and AI. Draw one card and teach it in one minute to a family member, using one drawing and one example you invented. Your listener asks one question. Then swap. At the end, put the cards in two piles: the ideas you could teach well now, and the ideas you want to practise again, and write one practice task for each card in the second pile. If you have a computer or tablet, an adult can help you run one of the Python programs from this year and check your prediction.
Practice
1
Fill in the OR table for a buzzer that sounds when the door is open OR the window is open.
Door open
Window open
Buzzer
0
0
?
0
1
?
1
0
?
1
1
?
The output is 0 only when both are 0. So the rows are 0 0 → 0, 0 1 → 1, 1 0 → 1 and 1 1 → 1.
2
What does the program print? Work out each line in order, and remember that not is worked out first, then and, then or.
Python
1a = False2b = True3print(not a and b)
4print(a or b andnot b)
The first line prints True: not False is True, and True and True is True. The second line prints False: b and not b is False, and False or False is False.
3
Use the pattern from the spam examples to label a message without the word WIN from an unknown sender. Then explain why a spam filter that learns should keep getting new examples.
It is not spam, because the pattern says spam only appears when the message has WIN and the sender is unknown. New examples help the system to learn new tricks and show cases it has never seen, so its mistakes can be corrected.
4
The sprinkler program is used with the readings 2, 3, 5 and 6. What does it print each time? Which two readings are the boundary values for the branches?
Python
1soil = int(input("Soil dryness 0 to 10? "))
2if soil < 3:
3print("Water a lot")
4elif soil < 6:
5print("Water a little")
6else:
7print("No water")
2 prints Water a lot, 3 and 5 print Water a little, and 6 prints No water. The boundary values are 3 and 6 (the first values that go into the Water a little and No water branches).