Medium1 markExtended Response
Fundamentals of algorithmsGeneraldebuggingalgorithmslogic error

AQA GCSE · Question 11.2 · Fundamentals of algorithms

The algorithm in Figure 10 contains a logic error on line 11.
Describe how the error on line 11 can be corrected.

How to approach this question

1. Identify the purpose of the `IF` statement on line 11. It is supposed to check if the `startYear` is valid (before 2000). 2. Analyse the current logic: `IF startYear < 2000 THEN OUTPUT "error"`. This is incorrect because a year before 2000 is valid. 3. Determine the correct logic. An error should be shown if the year is *not* before 2000, i.e., if it is greater than or equal to 2000. 4. Formulate the correction. The condition `startYear < 2000` should be changed to `startYear >= 2000`.

Full Answer

The `IF` condition on line 11 is incorrect. It should check for invalid years (2000 or later), but it currently flags valid years (before 2000) as errors. The correction is to change the condition from `startYear < 2000` to `startYear >= 2000`. Alternatively, the `THEN` and `ELSE` blocks (lines 12 and 14) could be swapped.
A logic error is when code runs without crashing but produces an incorrect or unexpected result. In Figure 10, the algorithm is supposed to accept start years that are before 2000. The code on line 11 is `IF startYear < 2000 THEN`. If this condition is true (e.g., `startYear` is 1999), it executes line 12, which outputs an error message. This is the opposite of what is intended. The valid years are being treated as errors. To correct this, the condition needs to identify the *invalid* years. A year is invalid if it is 2000 or later. Therefore, the condition should be changed to `IF startYear >= 2000 THEN`. This will correctly identify invalid years and show the error message, while valid years will proceed to the `ELSE` block where `validChoice` is set to `True`.

Common mistakes

✗ Simply stating "the logic is wrong" without explaining how to fix it.\n✗ Suggesting a fix that doesn't correct the error or introduces another one.

Practice the full AQA GCSE Computer Science Paper 1 Python

31 questions · hints · full answers · grading

More questions from this exam