Logic Power 0 / 29
Logic Rank Error Generator

2.3

Robust Programs (Error Identification)

Question 1 [4 Marks]
(a) Define the term Syntax Error.
[1]

(b) Define the term Logic Error.
[1]

(c) A programmer is writing a game in a High-Level Language (Python).
(i) When is a Syntax Error usually detected? (Choose one: During writing/translation OR While the program is running).
[1]

(ii) When is a Logic Error usually detected?
[1]
✅ Mark Scheme

1a: An error in the grammar/spelling/rules of the programming language. (1)

1b: The program runs but produces an incorrect/unexpected result. (1)

1c: (i) During writing / translation (compilation/interpretation). (1)
(ii) During execution / While running. (1)

Score:
Question 2 [6 Marks]
The following code is intended to ask for a user's age and print it next year. It contains three Syntax Errors.
01 age = input("Enter your age: ") 02 next_age = age + 1 03 if next_age >= 18 04 Print("You are an adult next year") 05 else: 06 print("You are a minor")
Identify the line number and write the correction for each of the three syntax errors.
[6]

Error 1: Line ........... Correction: ....................................................................................

Error 2: Line ........... Correction: ....................................................................................

Error 3: Line ........... Correction: ....................................................................................
✅ Mark Scheme

2: Error 1 (Line 02): next_age = int(age) + 1 (Casting Error) (2)
Error 2 (Line 03): if next_age >= 18: (Missing Colon) (2)
Error 3 (Line 04): print(...) (Case Error) (2)

Score:
Question 3 [5 Marks]
A programmer writes a while loop to count down from 10 to 1. The program runs, but the screen fills with 10 forever and never stops.
01 count = 10 02 while count > 0: 03 print(count) 04 # End of loop
(a) State the name of the logical error occurring here (specifically regarding the loop).
[1]

(b) Explain why this error is occurring based on the code above.
[2]

(c) Write the one line of code that is missing and needs to be added inside the loop to fix this.
[2]
✅ Mark Scheme

3: (a) Infinite Loop (1)
(b) The variable count is never updated/changed inside the loop (1) so the condition count > 0 remains True forever (1).
(c) count = count - 1 (or count -= 1) (2)

Score:
Question 4 [5 Marks]
A theme park ride allows people to enter if they are Over 12 years old OR Taller than 140cm.
The programmer writes the following algorithm:
01 age = 10 02 height = 150 03 if age > 12 and height > 140: 04 print("Allowed") 05 else: 06 print("Denied")
(a) Determine the output of the current algorithm.
[1]

(b) The output in part (a) is a Logic Error. Explain why the result is incorrect based on the rules of the theme park.
[2]

(c) Refine line 03 to correct the logic error.
[2]
✅ Mark Scheme

4: (a) "Denied" (1)
(b) The user meets one criteria (Height 150 > 140), so they should be allowed. The AND operator requires both to be true, excluding valid customers. (2)
(c) if age > 12 or height > 140: (2)

Score:
Question 5 [6 Marks]
A student writes a program to calculate the average of three test scores.
The program runs without crashing, but the result is mathematically wrong.
score1 = 10 score2 = 20 score3 = 30 average = score1 + score2 + score3 / 3 print(average)
(a) The expected output is 20.0. State the actual output of the code above.
[2]

(b) Explain the specific logic error regarding the Order of Operations (BIDMAS) in the code.
[2]

(c) Rewrite the line calculating the average to fix the error.
[2]
✅ Mark Scheme

5: (a) 40.0 (2)
(b) Division happens before addition (1). Only score3 is being divided by 3, not the total (1).
(c) average = (score1 + score2 + score3) / 3 (2)

Score:
Question 6 [3 Marks]
An array students contains 5 names.
students = ["Ali", "Bea", "Cam", "Dan", "Eve"]
The programmer wants to print all names using a for loop.
for i = 0 to 5: print(students[i])
This code causes a crash (Index Out of Bounds) on the final iteration.

(a) Explain why the loop crashing on i = 5 is a Logic Error in the design of the loop range.
[2]

(b) Refine the first line of the loop to fix this error.
[1]
✅ Mark Scheme

6: (a) Array indices start at 0. The last item is at index 4, but the loop tries to access index 5. (2)
(b) for i = 0 to 4 (or range(5) in Python) (1)

Score: