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

Divide and conquer

Week 13 · 1.7 Software development · 3 lessons
3

Write a bit, test a bit

Computing 8: Topic 1.7, pp. 150–172
GoalDescribe iterative development and follow a program through three versions, testing each one.
New words
iterative development · building a program in small versions: write a little, test it, then change and improve itversion · one stage of a program, saved before the next change is madetest · to run a program with chosen data to see whether it gives the results you expect
Explanation

Experts rarely write a whole program and then test it once. They use iterative development. First they write a small version that does one job. Next they test it. If it is wrong they fix it. If it is right they add the next feature, and test again. This repeats until the program does everything it should. Each version is a working step. A mistake is easy to find because only a little has changed since the last test. If the whole program is written first, a mistake could be hiding anywhere. A beginner’s first version may be very small, and that is fine.

write a littletest itchange or add
Worked examples
Python
1tickets = int(input("Tickets? "))
2print(tickets * 8)
Output
24
Version 1 of a ticket program for a school play: it only multiplies. Test: typing 3 gives 24, which is correct (3 × 8). The programmer is happy and moves on.
Python
1tickets = int(input("Tickets? "))
2total = tickets * 8
3if tickets >= 5:
4    total = total - 5
5print(total)
Output
35
Version 2 adds a rule: five or more tickets get 5 off. It is tested again with 3 (no discount, 24) and with 5. 5 × 8 = 40, minus 5 is 35, which is correct.
VersionWhat was addedTest dataResult
1price for tickets324, correct
25 off for 5 or more tickets535, correct
3a clear message4Total price: 32, correct
Version 3 improves the message. Each version was tested before the next one was started.
Class activity

Paper aeroplanes (no computer). Fold a simple paper aeroplane and fly it from a line on the floor. Measure the distance with a ruler or in footsteps. Change only one thing, such as the wing size or a nose fold, and fly it again. Record each version in a table: version, what changed, distance. Make three versions. Which change helped most? Why is changing only one thing at a time useful? Compare this with writing a program in versions. If you have a computer or tablet, ask an adult to help you run version 1 of the ticket program.

Practice
1
Put these steps of iterative development in a sensible order: test the version, write a small first version, add the next feature, fix any mistakes.
2
Version 1 of a program reads a number of cups and prints cups * 3. Write version 2: it adds a charge of 2 for delivery when the number of cups is more than 0. What is the output for 4 cups?
Python
1cups = int(input("Cups? "))
2print(cups * 3)
3
A test of version 2 is shown. Version 1 passed its test earlier. In which version was the mistake added, and what is wrong? Fix it.
VersionTest dataExpectedActual
132424
2 (uses tickets > 5)53540
4
Explain why writing and testing a small version at a time makes mistakes easier to find than writing the whole program first.