1
Number machines
Computing 2: Unit 10, pp. 134–148
GoalFollow an algorithm that works on a number, and say its output.
New words
input · the data we give to an algorithmoutput · the result an algorithm givespredict · to say what will happen before it happens
Explanation
An algorithm can work on a number that we give it. The number we give is the input. The algorithm does each step in order. What it shows at the end is the output. Before we run an algorithm, we can predict the output. We do each step with the input, just as a computer would.
input: 3→add 2→output: 5
Worked examples
| Step | Instruction |
|---|---|
| 1 | Start |
| 2 | Enter a number |
| 3 | Take away 1 |
| 4 | Show the number |
| 5 | Stop |
| Input | Output |
|---|---|
| 6 | 5 |
| 10 | 9 |
| 3 | 2 |
input: 4→double→add 1→output: 9
An algorithm with two steps: enter a number, double it, then add 1. With the input 4, the number becomes 8 and then 9. The output is 9.Class activity
Number machine game (pairs): one child is the machine and thinks of a secret rule, such as “add 3” or “take away 1”. The other child says a number, which is the input. The machine says the output. After three tries, guess the rule. Swap places. Use counters if you want to check.
Practice
1
The algorithm is: enter a number, add 4, show the number. The input is 5. Predict the output.
input: 5→add 4→output: ?
9, because 5 + 4 = 9.
2
The algorithm is: enter a number, take away 2, show the number. The input is 7. What is the output?
5.
3
Tom types 8 and the machine shows 11. Which number is the input and which is the output?
The input is 8 and the output is 11.
4
The algorithm adds 3. Find the outputs for the inputs 2 and 6.
| Input | Output |
|---|---|
| 2 | ? |
| 6 | ? |
5 and 9.