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

Year round-up

Week 30 · Review: Term 3 · 3 lessons
3

Gates, learning and sensing

Computing 8: Topics 3.1–4.5, pp. 230–299
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.

Worked examples
A: cover offB: lifeguardNOT BA AND NOT B
0010
0100
1011
1100
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
yesnospam
yesyesnot spam
nononot spam
noyesnot spam
yesnospam
yesyesnot 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.
Python
1rain = int(input("Rain sensor 0 to 10? "))
2if rain >= 6:
3    print("Close window")
4elif rain >= 3:
5    print("Half close")
6else:
7    print("Leave open")
Output
Half close
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 openWindow openBuzzer
00?
01?
10?
11?
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 = False
2b = True
3print(not a and b)
4print(a or b and not b)
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.
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:
3    print("Water a lot")
4elif soil < 6:
5    print("Water a little")
6else:
7    print("No water")