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

Words before code

Week 1 · 1.1 Pseudocode · 3 lessons
2

Change the plan

Computing 9: Topic 1.1, pp. 11–24
GoalWork out what an algorithm does, then edit it to change what it does or to add a new task.
New words
edit · to change an algorithm so that it does something different or does an extra jobdry run · following an algorithm by hand, line by line, with test datatest data · values chosen to try an algorithm, including values on the edgesboundary value · a value exactly on the edge of what is allowed, such as the 8 in ‘8 or less’
Explanation

Before you change an algorithm you must find out what it does. Read it line by line and then dry run it with some data. Never leave this step out. Then plan the change: which line must be different, and what will the new line be? There are two kinds of edit. You can change what it does, for example a new number, condition or message. Or you can add a task, which means new lines, and sometimes a new variable. After the edit, test again with a range of data, including boundary values. One test is not enough. If the edited algorithm gives a wrong result, go back through the steps and try again.

Worked examples
Pseudocode
1INPUT people
2IF people <= 6 THEN
3    OUTPUT "Lift is OK"
4ELSE
5    OUTPUT "Too many people"
6ENDIF
A lift sign. The lift takes 6 people. With 5 and 6 people typed the output is Lift is OK, because 6 <= 6 is true. With 7 people it says Too many people. Reading it first shows that the number 6 sits in the condition.
Test dataExpected outputOutput of edited algorithm
3Lift is OKLift is OK
8Lift is OKLift is OK
9Too many peopleToo many people
20Too many peopleToo many people
Edit 1: a bigger lift takes 8 people. Only one number has to change, in line 2. The testing matters most. The data 8 and 9 sit on the boundary, so they show whether <= is right. Data such as 3 would give Lift is OK before and after the edit, so it proves little.
Pseudocode
1INPUT people
2IF people <= 8 THEN
3    OUTPUT "Lift is OK"
4ELSE
5    extra ← people - 8
6    OUTPUT "Too many. Please leave: ", extra
7ENDIF
Edit 2: add a task. The sign must also say how many people have to get out. A new variable extra is made in the ELSE branch, because it is only needed there. With 11 people typed the output is Too many. Please leave: 3. With 9 people it is Too many. Please leave: 1.
Class activity

Edit swap (no computer). Each player writes a short algorithm on paper, for example a canteen sign that shows Open if the hour typed is between 8 and 14, and Closed otherwise, using AND. Swap papers. Your partner dry runs it with three test numbers, then makes one change (a new time) and one extra task (for example, also show Lunch served when the hour is 12). Then you check each other’s edits with boundary values. Talk about which test values were most useful. If you have a computer or tablet, an adult can help you type one edited algorithm in Python.

Practice
1
Dry run this algorithm with 1, 2, 5 and 6 hours. What is the fee each time?
Pseudocode
1INPUT hours
2fee ← 0
3IF hours > 2 THEN
4    fee ← (hours - 2) * 3
5ENDIF
6OUTPUT "Parking fee: ", fee
2
Edit the parking algorithm in task 1 so that the first 3 hours are free and each extra hour costs 4. Write the new lines. Then complete the table of expected fees for the edited algorithm.
Hours typedExpected fee after the edit
3?
4?
7?
3
The parking algorithm must also show Long stay, as an extra output, when the hours are more than 8. The fee must still be shown. Write the extra lines and say where they go.
4
A pupil changes the lift limit from 6 to 8, tests with 3 people and says it works. Why is this not enough? Name three better test values and say why they are better.