Medium1 markExtended Response
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.
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
Q01.1Figure 1 shows an algorithm, represented using pseudo-code, which assigns a different value to fo...EasyQ01.2The variable `x` is assigned a value using the statement:
`x ← LEN(state)`
Using Figure 1, what ...EasyQ01.3What is the result of concatenating the contents of the variables `city` and `landmark` in Figure 1?EasyQ01.5The subroutine `POSITION` finds the first position of a character in a string.
For example, `POSI...EasyQ02.1Figure 2 shows an algorithm that uses integer division which has been represented using pseudo-co...Easy
Expert