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

Predict first

Week 24 · Unit 10: Be a storyteller · 3 lessons
2

Predict a longer algorithm

Computing 2: Unit 10, pp. 134–148
GoalPredict the output of an algorithm with three steps by writing down the number after each step.
New words
step · one instruction in an algorithmkeep track · to write down what happens after each stepcheck · to run the algorithm and see if the prediction was right
Explanation

A longer algorithm has more steps. Do one step at a time. Write down the number after each step. The last number is the output. Then run the algorithm and check your prediction. If it is different, look for the step where you made a mistake.

After stepNumber
enter the number3
add 25
double10
take away 19
Worked examples
Enter a number, double it, add 3 and show it. With the input 5 the number goes 5, 10, 13. The output is 13.
OrderInputAfter step 1Output
double, then add 1367
add 1, then double348
The order of the steps matters. Take the input 3. Double and then add 1 gives 7. Add 1 and then double gives 8.
Predicting is not guessing. We work through every step. If our prediction is wrong, we look for the step where we made the mistake.
Class activity

Prediction race: write an algorithm of three steps on a card, for example “enter a number, add 2, double”. One child predicts the output for the input 4 on paper. Another child uses 4 counters: add 2 more counters, then make a second pile the same size and count all. Compare. Did the prediction match?

Practice
1
The input is 4. The steps are: double, add 1, take away 3. Predict the output.
2
The input is 1. The steps are: add 3, take away 2, add 4. What is the output?
3
The algorithm is “add 2, then double”. Malika gets 12 for the input 5. Is she right? What did she do?
After stepNumber
enter the number5
add 2?
double?
4
True or false: if the input changes, the output stays the same.