Oxford Cambridge and RSA
GCSE (9-1) Computer Science
Algorithms & Programming
J277/02
Topic: 2.2 Programming Advanced
Time allowed: 45 minutes
Centre number Candidate number
First name Last name
INSTRUCTIONS INFORMATION
Turn over
Section A: Prediction & Syntax
1
(a) State the value of result in each of the following assignment statements.
(Note: DIV is integer division, MOD is modulus/remainder, ^ is exponentiation).
[4]
Code Statement Value of result
result = 10 / 2
result = 10 DIV 3 (or 10 // 3)
result = 10 MOD 4 (or 10 % 4)
result = 2 ^ 4 (or 2 ** 4)
2
Given that x = 5 and y = 10, state whether the following expressions evaluate to True or False.
[3]
Expression Result (True/False)
x > 5 OR y == 10
x < 10 AND y != 10
NOT (x == 5)
3
A programmer uses the line average = total / count.
Another programmer uses average = total DIV count.

Explain the difference in the result produced by these two operators and why the choice of data type for average matters.
[3]
Turn over
Section B: Syntax & Debugging
4
A common error in programming is confusing the assignment operator with the comparison operator.

(a) Identify the symbol used for Assignment.
[1]

(b) Identify the symbol used for Comparison (Equal to).
[1]

(c) Write a line of code that checks if a variable score is equal to 100.
[1]
5
The following code is intended to check if a user is a teenager (aged 13 to 19 inclusive).
It contains a Logic Error.
age = int(input("Enter age: ")) if age > 13 OR age < 19: print("You are a teenager") else: print("You are not a teenager")
(a) Explain why the logic age > 13 OR age < 19 is incorrect. Give an example of an age that would produce the wrong output.
[2]

(b) Rewrite the if statement line to correctly check if the age is between 13 and 19 (inclusive).
[2]
6
Look at this snippet:
price = 10 print("The price is " + price)
The code crashes. Explain the error using the correct technical term (e.g., Syntax, Logic, Runtime) and describing the data type conflict.
[2]
Turn over
Section C: Trace Tables & Algorithms
7
Trace the execution of this algorithm which uses arithmetic updates.
a = 10 b = 2 c = 0 WHILE a > b a = a - 2 b = b + 1 c = c + b ENDWHILE print(c)
[5]
a b c Condition a > b (T/F) Output
10 2 0 True
8
A security gate opens only if:
  • The alarm is OFF (False).
  • AND The correct keycard is scanned (True) OR the master code is entered (True).
Complete the code snippet below using the correct Boolean Operators and Parentheses.
[2]
alarm = False keyCard = True masterCode = False if (NOT alarm) ___________ (keyCard == True ___________ masterCode == True): print("Gate Open") else: print("Access Denied")
Turn over
Section D: Mastery & Refining
9
A student has written code to assign a team colour based on a user's ID number.
  • ID 1, 2, 3 = "Red"
  • ID 4, 5, 6 = "Blue"
  • Anything else = "Spectator"
id = int(input("Enter ID")) if id == 1: print("Red") if id == 2: print("Red") if id == 3: print("Red") if id == 4: print("Blue") if id == 5: print("Blue") if id == 6: print("Blue")
Rewrite this code to be more efficient using Comparison Operators (<, >, <=, >=) and Boolean Operators (AND, OR) to reduce the number of lines.
[4]
10
Write a program for a "Number Analyser".
The program must:
  • Ask the user to input a whole number.
  • Cast the input correctly.
  • Check if the number is Even or Odd (Hint: Use MOD).
  • Output "Even" or "Odd".
  • Check if the number is positive AND a multiple of 10.
  • Output "Big Ten" if true.
  • Check if the number is negative.
  • Output "Negative number".
[6]
11
You have a Record called Product with fields: Name, Price, Stock.
Write a line of code to decrease the Stock of a record named item1 by 5.
[2]
END OF QUESTION PAPER