GoalExplain why the instructions given to a computer must be precise, detailed, in the right order and carried out one at a time.
New words
instruction · a command to do something, or a piece of information about how to do itprecise · exact and clear, with nothing left for the reader to guessprogram · a list of instructions for a computerprocessor · the part of the computer, the CPU, that follows the instructions
Explanation
People can follow a loose instruction because they fill the gaps with what they already know. “Tidy the desk” makes sense to a friend who knows your desk. A computer has no experience to use. It has only the instructions it is given at that moment. So every instruction must be precise: it says which thing, where and how much. A program also needs enough detail, because a step that is missing is a step that never happens. The steps must come in the right order, because a later step often needs the result of an earlier one. The processor then carries the steps out one at a time, like a person with only one pair of hands.
Loose instruction
What a computer could not know
Precise version
Water the plant
which plant, and how much water
Pour 200 ml of water into the pot on the left shelf
Add the numbers
which numbers, and where the answer goes
Add 7 and 5 and store the answer in total
Make it bigger
which part, and by how much
Change the width of the box from 4 cm to 6 cm
Worked examples
Step
Detail the robot still needs
1 Go to the table
which table, and how many steps to walk
2 Pick up the cup
which cup, and hold it by the handle, not by the rim
3 Walk to the shelf
which shelf, and how to avoid the chair on the way
4 Put the cup on the shelf
which shelf height, and where along the shelf
Telling a helper robot to put a cup on a shelf. The short instruction hides many smaller ones. Each step in the list still needs details that a person would guess, so the writer keeps adding them until nothing is left to guess.
Python
1print(total)
2total = first + second
3first = 84second = 3
Output
NameError: name 'total' is not defined
The right order. In this program the first line asks for the value of total before any line has created it, so the computer stops with an error. With the lines in the right order (first = 8, second = 3, total = first + second, print(total)) the program prints 11. The computer cannot see that line 2 should have come first.
Order of steps
Working
Result
add 5, then double
(10 + 5) × 2
30
double, then add 5
10 × 2 + 5
25
Same steps, different order, different answer. Start with 10 and use two steps: add 5, and double. Adding first gives (10 + 5) × 2 = 30. Doubling first gives 10 × 2 + 5 = 25. A computer does what the list says in the order written, so the writer must choose the order that gives the answer wanted.
Class activity
The literal partner (no computer). Draw a 3 × 3 grid on paper and put six coins or buttons in a pile. Write six numbered instructions that place the coins to make a pattern that only you have seen, for example an L-shape. Do not tell your partner what the pattern is. Your partner plays the processor: they do exactly what each line says, one line at a time, and nothing more. When they finish, compare the grid with your pattern. Find the line that was not precise or detailed enough, rewrite it, and swap roles.
Practice
1
Write precise or vague for each instruction.
Instruction
Precise or vague?
(a) Move the piece.
?
(b) Move the red piece two squares to the right.
?
(c) Save the file.
?
(d) Save the file called notes in the folder Homework.
?
(e) Do the sum.
?
(a) vague: which piece, and where? (b) precise; (c) vague: which file, and where? (d) precise; (e) vague: which sum?
2
This program should print the cost of 4 boxes at 6 each, but it stops with the error shown. Explain why it stops, then write the three lines in an order that works. What does it print?
Python
1print(amount)
2amount = boxes * 63boxes = 4
Output
NameError: name 'amount' is not defined
Line 1 asks for amount before any line has created it, so the computer does not know the name. Working order: boxes = 4, amount = boxes * 6, print(amount). It prints 24.
3
Start with 6. Complete the table. What do you notice?
Order of steps
Working
Result
subtract 2, then multiply by 3
(6 − 2) × 3
?
multiply by 3, then subtract 2
6 × 3 − 2
?
(6 − 2) × 3 = 12 and 6 × 3 − 2 = 16. The same two steps in a different order give a different result, so the order matters.
4
Write four numbered instructions for a friend who has never done it before, telling them how to wash and dry their hands. Make each one precise, and put them in the right order.
Model answer: 1 Turn on the tap and wet both hands. 2 Put a small amount of soap on one palm. 3 Rub both hands together, including between the fingers and the backs, for about 20 seconds, then rinse under the water. 4 Turn off the tap and dry both hands with a clean towel. Check that each step says what to use and for how long, and that drying comes last.