Time left1:30:00 Answered 0 of 29 80 marks
OCR J277/02 1 hour 30 minutes 80 marks Full length paper

GCSE Computer Science Paper 2 B: Computational Thinking, Algorithms and Programming

Instructions

Time allowed
1 hour 30 minutes
Total marks
80
Sections
Section A, 50 marks; Section B, 30 marks
Calculator
No calculator is permitted.
  • Answer all the questions.
  • Write the Section B programs in Python, so they can be run and marked here.
  • OCR advises about 50 minutes on Section A and about 40 minutes on Section B.

Questions

80 marks

Section A 50 marks

Answer all the questions in this section.

1(a)Tick one box in each row to show which computational thinking technique is being used.2 marks
AbstractionDecomposition
Breaking the job of building a game into designing levels, writing the physics and creating the sound
Storing a player only as a position, a health value and a score

Tick one box in each row.

Mark scheme0 / 2
  • LBreaking the job of building a game into designing levels, writing the physics and creating the sound: Decomposition
  • LStoring a player only as a position, a health value and a score: Abstraction
Model answer

Splitting a problem into parts is decomposition. Keeping only the details that matter is abstraction.

Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

1(b)A binary search is used to find 52 in this list. Complete the table to show the item checked at each comparison.3, 8, 12, 19, 25, 31, 40, 52, 663 marks
ComparisonItem checked
1
2
3

Mark scheme0 / 3
  • L25
  • L40
  • L52
Model answer

With indexes 0 to 8, the middle is index 4, which is 25. 52 is larger, so the search continues in indexes 5 to 8, whose middle is index 6, 40. 52 is larger again, so it continues in 7 to 8, whose middle is index 7, which holds 52.

Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

1(c)State one advantage of a linear search over a binary search.1 mark
State

Mark scheme0 / 1
  • LIt works on an unsorted list (or is simpler to write)
Model answer

A linear search works on a list in any order, whereas a binary search only works on a sorted list.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.

Think this answer or mark scheme is wrong? Report it

1(d)A bubble sort puts this list into ascending order: 6, 2, 9, 4, 1Complete the table to show the list after the first pass.2 marks
Position 0Position 1Position 2Position 3Position 4

Mark scheme0 / 2
  • L2, 6, 4 in positions 0 to 2: 2, 6, 4
  • L1, 9 in positions 3 and 4: 1, 9
Model answer

6 and 2 swap, 6 and 9 stay, 9 and 4 swap, 9 and 1 swap: 2, 6, 4, 1, 9. The largest value has moved to the end.

Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

1(e)Describe how a merge sort would sort the list 6, 2, 9, 4.3 marks
Describe

Mark scheme0 / 3
  • LThe list is split repeatedly until each sublist holds one item
  • LPairs of sublists are merged in order: 2, 6 and 4, 9
  • LThe two sorted lists are merged by comparing their first items, giving 2, 4, 6, 9
Model answer

The list is split in half, then in half again, until there are four lists of one item: 6, 2, 9 and 4. Neighbouring lists are merged in order, giving 2, 6 and 4, 9. Those two lists are then merged by repeatedly comparing their front items and taking the smaller, giving 2, 4, 6, 9.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.

Think this answer or mark scheme is wrong? Report it

2(a)Tick one box in each row to show the most suitable data type.5 marks
IntegerRealBooleanCharacterString
The number of students in a class
The price of a ticket in pounds
Whether a seat is booked
A form group, such as 10B
A single grade, such as A

Tick one box in each row.

Mark scheme0 / 5
  • LThe number of students in a class: Integer
  • LThe price of a ticket in pounds: Real
  • LWhether a seat is booked: Boolean
  • LA form group, such as 10B: String
  • LA single grade, such as A: Character
Model answer

Whole numbers are integers, money is real, yes or no is Boolean, 10B is a string because it has more than one character, and a single letter is a character.

Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

2(b)Write the value of each expression.3 marks

Mark scheme0 / 3
  • L2
  • L3
  • L16
Model answer

17 divided by 5 is 3 remainder 2, so MOD gives 2 and DIV gives 3. 2 to the power 4 is 16.

Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

2(c)userAge holds the string "14". Which line converts it into an integer?1 mark

Tick one box.

Mark scheme0 / 1
  • LC age = int(userAge)
Model answer

int() casts a string to an integer.

Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

2(d)Complete the trace table for this algorithm.4 marks
OCR reference language
total = 0
for i = 1 to 3
    total = total + i * 2
next i
print(total)
itotal
1
2
3
output

Mark scheme0 / 4
  • L2
  • L6
  • L12
  • L12
Model answer

Each pass adds i x 2: 0 + 2 = 2, 2 + 4 = 6, 6 + 6 = 12, and 12 is printed.

Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

2(e)Explain the difference between a local variable and a global variable.2 marks
Explain

Mark scheme0 / 2
  • LA local variable can only be used inside the subroutine where it is declared
  • LA global variable can be used anywhere in the program
Model answer

A local variable is declared inside a subroutine and can only be used there; it disappears when the subroutine ends. A global variable is declared in the main program and can be used anywhere in it.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.

Think this answer or mark scheme is wrong? Report it

3(a)Complete the truth table for P = (A AND B) OR NOT C.4 marks
ABCP
000
001
010
011
100
101
110
111

Mark scheme0 / 4
  • LRows 1 and 2: 1, 0
  • LRows 3 and 4: 1, 0
  • LRows 5 and 6: 1, 0
  • LRows 7 and 8: 1, 1
Model answer

P is 1 whenever C is 0. When C is 1, P is only 1 if A and B are both 1, which is the last row.

Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

3(b)Which logic gate gives an output of 1 only when both of its inputs are 1?1 mark

Tick one box.

Mark scheme0 / 1
  • LA AND
Model answer

AND needs both inputs to be 1.

Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

3(c)A burglar alarm sounds (Q) when it is set (S) and either the door (D) or a window (W) is opened. Write a Boolean expression for Q.1 mark

Mark scheme0 / 1
  • LS AND (D OR W)
Model answer

Q = S AND (D OR W). The brackets matter: without them S AND D OR W would sound whenever a window opened.

Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

3(d)What is the value of NOT (1 AND 0) OR 0?1 mark

Mark scheme0 / 1
  • L1
Model answer

1 AND 0 is 0, NOT 0 is 1, and 1 OR 0 is 1.

Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

4(a)Tick one box in each row to show which validation check is described.4 marks
Range checkPresence checkLength checkFormat check
A password must have at least 8 characters
A postcode must match the pattern of letters and digits
An age must be between 0 and 120
A username cannot be left blank

Tick one box in each row.

Mark scheme0 / 4
  • LA password must have at least 8 characters: Length check
  • LA postcode must match the pattern of letters and digits: Format check
  • LAn age must be between 0 and 120: Range check
  • LA username cannot be left blank: Presence check
Model answer

Minimum characters is a length check, a pattern is a format check, limits are a range check, and not blank is a presence check.

Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

4(b)Describe what is meant by defensive design, giving two examples.3 marks
Describe

Mark scheme0 / 3
  • LDesigning a program to anticipate misuse and handle unexpected input, so it does not crash or behave wrongly
  • LExample: input validation or input sanitisation
  • LExample: authentication, such as usernames and passwords, or maintainable code with comments and naming
Model answer

Defensive design means planning for misuse: anticipating how users might enter unexpected or malicious data and making sure the program copes rather than crashing or giving wrong results. Examples are validating every input, and authentication so only allowed users can use the program.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.

Think this answer or mark scheme is wrong? Report it

4(c)A program accepts whole numbers from 1 to 10. Tick one box in each row to show the type of each test value.4 marks
NormalBoundaryInvalidErroneous
5
10
11
ten

Tick one box in each row.

Mark scheme0 / 4
  • L5: Normal
  • L10: Boundary
  • L11: Invalid
  • Lten: Erroneous
Model answer

5 is typical valid data, 10 is at the edge of the range, 11 is the right type but out of range, and ten is the wrong type of data.

Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

4(d)Tick one box in each row to show whether each describes a compiler or an interpreter.2 marks
CompilerInterpreter
Translates the whole program at once into an executable file
Translates and runs one line at a time
Reports every error after translating the whole program
Stops at the first error it meets

Tick one box in each row.

Mark scheme0 / 2
  • L1 mark for both: Translates the whole program at once into an executable file: Compiler; Translates and runs one line at a time: Interpreter
  • L1 mark for both: Reports every error after translating the whole program: Compiler; Stops at the first error it meets: Interpreter
Model answer

A compiler translates everything first and produces an executable; an interpreter translates and runs line by line.

Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

4(e)Describe two features of an IDE that help a programmer to find and fix errors.4 marks
Describe

Mark scheme0 / 4
  • LError diagnostics that show where errors are and what they are
  • LThese point the programmer straight to the line to fix
  • LA debugger with breakpoints or stepping, or a variable watch
  • LThis lets the programmer pause the program and see the values of variables to find logic errors
Model answer

Error diagnostics highlight the line where a syntax error is and say what is wrong, so the programmer goes straight to it. Breakpoints pause the running program at a chosen line, so the programmer can step through it line by line and watch the variables change, which is how logic errors are found.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.

Think this answer or mark scheme is wrong? Report it

Section B 30 marks

A cinema uses a program to sell tickets. Answer all the questions in this section. Write your programs in Python.

5(a)Tickets cost £5.50 for under 16s, £8.00 for ages 16 to 64, and £6.00 for 65 and over.Complete the function ticketPrice so that it returns the price of one ticket for a person of the given age.4 marks
tickets.py

Mark scheme0 / 4
  • LReturns 5.50 for anyone under 16, including 15
  • LReturns 8.00 for ages 16 to 64, including both ends
  • LReturns 6.00 for 65 and over, including 65
  • LReturns the price rather than printing it
A program that scores full marks

Check the bands in order with if, elif and else, using < 16 and < 65 so that 16 and 65 fall in the right band.

Python
def ticketPrice(age):
    if age < 16:
        return 5.50
    elif age < 65:
        return 8.00
    else:
        return 6.00
Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

5(b)Write the main program. It must:ask how many tickets are wantedkeep asking until the number is between 1 and 10ask for the age of each personuse ticketPrice to add up the cost, then output the total.6 marks
tickets.py

Mark scheme0 / 6
  • LAsks for the number of tickets and one age per ticket
  • LRejects a number of tickets below 1 and asks again
  • LRejects a number above 10 and asks again
  • LUses a loop to repeat the validation
  • LUses ticketPrice to find each person's price
  • LOutputs the correct total for a mixed group, 19.5 for ages 10, 30 and 70
A program that scores full marks

Validate with a while loop, then loop once per ticket, adding ticketPrice(age) to a running total.

Python
def ticketPrice(age):
    if age < 16:
        return 5.50
    elif age < 65:
        return 8.00
    else:
        return 6.00

tickets = int(input("How many tickets? "))
while tickets < 1 or tickets > 10:
    tickets = int(input("Enter a number from 1 to 10: "))
total = 0
for i in range(tickets):
    age = int(input("Age: "))
    total = total + ticketPrice(age)
print("Total cost:", total)
Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

5(c)(i)A group of 4 or more members should get 10% off, but a group of exactly 4 is charged full price. Which line contains the logic error?1 mark
Python code
01 def discount(total, members):
02     if members > 4:
03         total = total * 0.9
04     return total

Tick one box.

Mark scheme0 / 1
  • LB 02
Model answer

Line 02 uses > 4, so a group of exactly 4 misses out. It should be >= 4.

Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

5(c)(ii)Write the corrected line.1 mark

Mark scheme0 / 1
  • Lif members >= 4:
Model answer

if members >= 4:

Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

6(a)The seats in one screen are stored in a 2D list called seats. Each item is "F" for free or "B" for booked, and an item is reached with seats[row][seat]. Write the value of each.2 marks
Python code
seats = [["B", "F", "F", "B"],
         ["F", "F", "B", "B"],
         ["B", "B", "B", "F"]]

Mark scheme0 / 2
  • LB
  • LF
Model answer

Row 0, seat 3 is the last item of the first row, B. Row 2, seat 3 is the last item of the last row, F.

Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

6(b)Complete the function countFree so that it returns the number of free seats in the 2D list it is given.4 marks
seats.py

Mark scheme0 / 4
  • LDefines countFree with one parameter
  • LReturns 5 for the seat plan above
  • LReturns 0 when every seat is booked
  • LWorks for a seat plan of any size
A program that scores full marks

Two nested loops visit every seat, counting those that hold F.

Python
def countFree(seats):
    free = 0
    for row in seats:
        for seat in row:
            if seat == "F":
                free = free + 1
    return free
Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

6(c)Complete the procedure bookSeat. If the seat is free it must change it to "B" and print Booked. If the seat is already booked it must print Already taken and change nothing.4 marks
seats.py

Mark scheme0 / 4
  • LDefines bookSeat with three parameters
  • LChanges a free seat to B
  • LPrints Booked when the seat was free
  • LPrints Already taken, and leaves a booked seat unchanged
A program that scores full marks

Check the seat first. Only a free seat is changed; a booked one just gets the message.

Python
def bookSeat(seats, row, seat):
    if seats[row][seat] == "F":
        seats[row][seat] = "B"
        print("Booked")
    else:
        print("Already taken")
Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

6(d)Explain why the cinema's program should save the seat plan to a file, rather than keep it only in the 2D list.2 marks
Explain

Mark scheme0 / 2
  • LThe list is held in RAM, so it is lost when the program closes or the power fails
  • LA file is kept in secondary storage, so the bookings can be loaded again later
Model answer

The 2D list only exists in RAM while the program runs, so every booking would be lost when the program closes or the computer restarts. Saving it to a file on secondary storage keeps the bookings permanently, so they can be loaded the next time the program starts.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.

Think this answer or mark scheme is wrong? Report it

7(a)The cinema wants a loyalty scheme in which members earn a free ticket for every 10 tickets they buy. Identify two inputs and one output this part of the program needs.3 marks
Identify

Mark scheme0 / 3
  • LAn input: the member's ID or name
  • LA second input: the number of tickets bought, now or in total
  • LAn output: the number of free tickets earned (or a message saying so)
Model answer

Inputs: the member's ID, and the number of tickets they have bought. Output: the number of free tickets they have earned.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.

Think this answer or mark scheme is wrong? Report it

7(b)Complete the function freeTickets so that it returns how many free tickets have been earned for the number bought: one for every 10.3 marks
loyalty.py

Mark scheme0 / 3
  • LReturns 2 for 25 tickets bought
  • LReturns 0 for 9 and 1 for 10, so the tenth ticket counts
  • LWorks for any number, such as 100 and 0
A program that scores full marks

Integer division by 10, DIV in OCR Exam Reference Language, // in Python, counts the complete tens.

Python
def freeTickets(bought):
    return bought // 10
Marked exactly against the mark scheme. Change it only if an examiner would accept your answer.

Think this answer or mark scheme is wrong? Report it

Machine mark 0 / 80