Worked example · Computer Science · Year 11
DCF: Producing → Evaluating and improving digital content
A complete, secure Year 11 answer, annotated so you can see which success criterion each part meets. It is also the answer key. Every result below was checked by running the program. The four faults are: line 7 uses > where it needs >=; line 13 uses or where it needs and; line 21 multiplies by 0.1 where it needs 0.9; lines 6 and 30 call int() without checking the input first, so words and empty boxes crash the program. Pupils may choose different test data; what matters is that every edge in R2, R3 and R4 is tested and the expected result comes from the requirements.
Every age test uses 3 lessons. Every lessons test uses age 9 and the surname Jones.
| No. | Input tested | Data | Type | Expected result | Actual result | Pass or fail |
|---|---|---|---|---|---|---|
| 1 | Age | 9 (lessons 3) | Typical | Booked: JON9, total £19.50 | Booked: JON9, total £19.50 | Pass |
| 2 | Age | 4 | Extreme | Accepted: Booked: JON4, total £19.50 | Age must be 4 to 16 | Fail |
| 3 | Age | 16 | Extreme | Accepted: Booked: JON16, total £19.50 | Booked: JON16, total £19.50 | Pass |
| 4 | Age | 3 | Erroneous | Age must be 4 to 16 | Age must be 4 to 16 | Pass |
| 5 | Age | 17 | Erroneous | Age must be 4 to 16 | Age must be 4 to 16 | Pass |
| 6 | Age | ten | Erroneous | Age must be 4 to 16 | Crash, ValueError at line 6 | Fail |
| 7 | Age | (blank) | Erroneous | Age must be 4 to 16 | Crash, ValueError at line 6 | Fail |
| 8 | Lessons | 1 | Extreme | Booked: JON9, total £6.50 | Booked: JON9, total £6.50 | Pass |
| 9 | Lessons | 10 | Extreme | 10% off: £65.00 × 0.9 = £58.50 | Booked: JON9, total £6.50 | Fail |
| 10 | Lessons | 5 | Typical, just under the discount | No discount: £32.50 | Booked: JON9, total £32.50 | Pass |
| 11 | Lessons | 6 | Extreme, first discounted block | 10% off: £39.00 × 0.9 = £35.10 | Booked: JON9, total £3.90 | Fail |
| 12 | Lessons | 0 | Erroneous | Lessons must be 1 to 10 | Booked: JON9, total £0.00 | Fail |
| 13 | Lessons | 11 | Erroneous | Lessons must be 1 to 10 | Booked: JON9, total £7.15 | Fail |
| 14 | Lessons | six | Erroneous | Lessons must be 1 to 10 | Crash, ValueError at line 30 | Fail |
Both inputs have typical, extreme and erroneous tests, and the discount is tested on both sides of the edge (5 and 6) and at the top (10). Expected results are worked out from R2 to R4, so the plan can catch the developer’s mistakes rather than copy them. Crashes are recorded with the error and the line. Evidences criteria 1 and 2.
| Tests that failed | Line(s) | What is wrong, and which requirement it breaks | Corrected code |
|---|---|---|---|
| 2 | 7 | age > 4 is false when the age is exactly 4, so the youngest allowed child is rejected. Breaks R2. | if age >= 4 and age <= 16: |
| 12, 13 | 13 | With or, every whole number passes: 0 is <= 10 and 11 is >= 1. Both conditions must be true. Breaks R3. | if lessons >= 1 and lessons <= 10: |
| 9, 11 | 21 | Multiplying by 0.1 keeps 10% of the price instead of taking 10% off. Breaks R4. | total = total * 0.9 |
| 6, 7, 14 | 6 and 30 | int() is called on whatever was typed, so a word or an empty box stops the program with ValueError. Breaks R2, R3 and R6. | Check with .isdigit() before converting. See the corrected functions below. |
The corrected validation functions and main program:
Rerunning all 14 tests with these changes: every test passes. Age 4 is booked as JON4 for £19.50, 10 lessons cost £58.50, 6 lessons cost £35.10, and 0, 11, “ten”, “six” and a blank box each give the correct message.
One row per fault, each with the exact line, the reason in terms of how Python evaluates it, the requirement it breaks, and a specific change. Moving the int() after an .isdigit() check fixes the crash in both places, and the full retest proves the changes worked. Evidences criteria 2 and 3.
(a) Siw, I ran 14 tests and 6 passed. There are four faults. Age 4 is wrongly rejected because line 7 uses > instead of >=. Any number of lessons is accepted, including 0 and 11, because line 13 uses or instead of and. Every discounted block is charged 10% of the price instead of 90%, so 6 lessons cost £3.90 instead of £35.10. Typing a word or leaving a box empty crashes the program at lines 6 and 30. The developer only tried typical values such as age 9 and 3 lessons, which all pass. Before the program goes on the desk, the four fixes must be made and all 14 tests run again.
Written for a client, not a programmer: it gives the pass rate, names each fault by its effect on the pool, explains why the developer missed them (only typical data was tried), and says what must happen next. Evidences criterion 4.
(b) The new function, with the Step 4 fix to the discount included:
Line 33 changes to price = block_price(int(lessons_text), int(age_text)). Age 4 is already allowed by check_age, so age <= 7 covers 4 to 7.
(c)
| Age | Lessons | Type | Expected result |
|---|---|---|---|
| 7 | 3 | Extreme, oldest at the lower price | 3 × £5.00 = Booked: JON7, total £15.00 |
| 8 | 3 | Extreme, youngest at the full price | 3 × £6.50 = Booked: JON8, total £19.50 |
| 5 | 6 | Typical, lower price with discount | 6 × £5.00 × 0.9 = Booked: JON5, total £27.00 |
The new function keeps the constant for the full price, fixes the discount, and puts the new rule in one place. The tests sit either side of the new edge (7 and 8) and combine the new price with the discount. Evidences criteria 3 and 5.