Oxford Cambridge and RSA
GCSE (9-1) Computer Science
Algorithms & Programming
J277/02
Topic: Unit 2.3 Robust Programs (Error Identification)
Time allowed: 45 minutes
Centre number Candidate number
First name Last name
INSTRUCTIONS INFORMATION
Turn over
Section A: Core Definitions
1
(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]
Section B: Syntax Spotting
2
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: ....................................................................................
Turn over
Section C: Logic Errors & "Ghost Topics"
3
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]
4
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]
Turn over
5
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]
6
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]
END OF QUESTION PAPER