Write down the rule you are testing
A passing example tells you that the program handled one input. It does not establish that every branch works. Start with a short statement of the expected behaviour, such as “hours must consist of decimal digits and have a value from 1 to 8 inclusive”. This contains two different checks. To test numeric range, choose well-formed numbers that vary in value. To test format, choose values that fail before a numeric range can be considered. If both features change at once, a failure gives less information about where to look.
| Case | Input | Expected output | What it checks |
|---|---|---|---|
| Normal | 4 | Accepted | A typical valid number |
| At minimum | 1 | Accepted | Lower limit included |
| Just below | 0 | Rejected | First value below the range |
| At maximum | 8 | Accepted | Upper limit included |
| Just above | 9 | Rejected | First value above the range |
| Empty | blank | Rejected | Presence and format checked before conversion |
| Incorrect type | 3.5 | Rejected | Decimal point excluded by the whole-number rule |
Add a column for actual output after you run the program. If a case fails, note the first difference rather than labelling the whole program broken. If every case fails with the same exception, first repair the error that prevents the program reaching its decisions. Then repeat the same tests. This is a regression check: it helps show that a fix did not break behaviour that already worked.
Read a traceback from the bottom
The bottom line often identifies the kind of error. ValueError from int(text) points to a conversion of unsuitable text. IndexError points to a position that is not in the list or string. NameError can mean a typo or that a line used a variable before it was assigned. Use the traceback line number to locate the instruction that failed, then trace back to where the value came from. Fix the cause rather than changing a later line merely to avoid the message.
For a logic error there may be no traceback. Try a temporary print of the condition or of the values before and after an update. Run one failing case. Then remove the debug output before checking the required format. In the sandbox, use Run with my input for that one test, then Check test cases to run the provided suite. If the code times out, look for a loop whose condition never changes. Stop it, trace the update and try again with the smallest possible input.
Check that two fields belong together
For fictional club records, validating a code format does not tell you whether it appears in the list. Matching a code in one row and a practice word in another row also does not authenticate the claimed pair. The match must be performed on the same record. A known pair exercises the successful path. A known code with another record’s word can expose a faulty pair of separate searches. An unknown code and an empty word exercise different failure paths. Keep the mock data inside the exercise and never reuse a real credential.
Practise a Paper 2 change request
A starter function accepts a ticket code if it starts with A and ends with three digits, for example A007. It currently uses code[0] == "A" and code[1:].isdecimal(). Find two shortcomings. Repair it so that the entire string has exactly four characters, the first is uppercase A, and the last three are decimal digits. Write normal, boundary and erroneous tests, including a blank entry, and predict the results before running.
Test the format of the output too
A program can calculate the right number and still fail an exact comparison. Look for extra prompts, debug prints, added spaces and values printed in the wrong order. Compare the two outputs line by line. Only change output formatting once you know that the underlying calculation is correct.