OCR GCSE Computer Science past paper questions, worked and runnable

OCR GCSE Computer Science (J277) Paper 2 past paper questions: trace tables, algorithms to write and fix, SQL and file handling. Each one is worked through step by step in OCR Exam Reference Language and Python, and can be run in your browser.

OCR J27747 worked answers5 papersfree

Paper 2, Computational thinking, algorithms and programming, is where the programming marks are. For each question below we say what it tests and link the lesson that teaches it. Where it says Worked answer, the question is gone through step by step, with a program you can run. We do not host the papers. Each one is linked on OCR's own site.

By type of question

Write a program

Explain

Trace table

SQL

Read the code

Complete the algorithm

Logic

Fix the code

Testing

Paper by paper

June 2025, Paper 2 (J277/02)

Sat 20 May 2025, 80 marks. On OCR's site: question paper, mark scheme.

QuestionWhat it testsTypeMarksLearn it
1Normal, boundary and invalid test data, and a 1 to 100 range checkTesting9F6.3 Testing and test data
F6.1 Defensive design and validation
F2.3 else, elif and Boolean operators
Worked answer
2(a), (b)Count the passes of a flowchart loop, and describe the kinds of iterationRead the code8F5.2 Flowcharts
F2.6 Condition-controlled loops: while
F2.5 Count-controlled loops: for
Worked answer
2(c)Two tools of an IDEShort answer4F6.6 The IDE
3(a)Show the steps of a merge sort on eight numbersExplain4F5.9 Merge sort and comparing algorithmsWorked answer
3(b), (c)Insertion sort, bubble sort, arrays, and naming a linear searchShort answer5F5.8 Insertion sort
F5.7 Bubble sort
F5.5 Linear search
4Complete an algorithm that reads numbers from a text file, and castingComplete the algorithm6F7.1 Reading and writing files
F1.8 Data types and casting
Worked answer
5(a), (b)A logic circuit from a description, and the truth table for A AND BLogic5F9.1 Logic gates and truth tables
F9.2 Logic circuits and expressions
Worked answer
5(c)Match abstraction, decomposition and algorithmic thinking to examplesShort answer3F4.4 Decomposition and abstraction
5(d)Validate a 4 character PIN that must not be 1234 or 4321Write a program6F6.1 Defensive design and validation
F3.1 String handling
F2.3 else, elif and Boolean operators
Worked answer
6(a)Input two passwords and check that they matchWrite a program4F1.7 Input from the user
F2.2 Selection: if
F1.6 Variables, constants and assignment
Worked answer
6(b)Correct four errors in an SQL statement, a record, and data typesSQL7F7.3 SQL: SELECT
F7.2 Relational databases
F1.8 Data types and casting
Worked answer
6(c)Write a function that returns a ticket price, then call itWrite a program6F4.1 Writing functions
F4.2 Parameters and return values
Worked answer
6(d)Trace a loop that totals an array, then refine itTrace table7F13.2 Trace tables
F3.4 Iterating over a list
F5.4 Trace tables
Worked answer
6(e)Sell tickets in a loop until none are leftWrite a program6F2.6 Condition-controlled loops: while
F2.7 Loop patterns
F13.4 Programming questions
Worked answer

June 2024, Paper 2 (J277/02)

Sat 21 May 2024, 80 marks. On OCR's site: question paper, mark scheme.

QuestionWhat it testsTypeMarksLearn it
1Match if, for and while to selection and iterationShort answer3F2.2 Selection: if
F2.5 Count-controlled loops: for
2Complete a flowchart that decides odd or even with MODComplete the algorithm4F5.2 Flowcharts
F1.9 Arithmetic operators
F2.2 Selection: if
Worked answer
3(a), (b)Define a syntax error, then correct two logic errors in a range checkFix the code6F6.4 Debugging logic errors
F1.4 Errors: syntax, runtime and logic
F2.3 else, elif and Boolean operators
Worked answer
3(c)Show a binary search for 10, its pre-requisite, and name merge sortExplain5F5.6 Binary search
F5.9 Merge sort and comparing algorithms
Worked answer
4Inputs and outputs of a video program, and defensive designShort answer4F6.1 Defensive design and validation
5A truth table for (A AND B) OR C and a circuit for NOT A AND (B OR C)Logic7F9.1 Logic gates and truth tables
F9.2 Logic circuits and expressions
Worked answer
6String methods: upper, left, right with a cast, and concatenationRead the code6F3.1 String handling
F1.8 Data types and casting
Worked answer
7Why use a low-level language, and the benefits of a compilerShort answer5F6.5 Languages and translators
8Maintainability, and a function that moves a character and keeps it in rangeWrite a program10F4.2 Parameters and return values
F1.5 Comments and readable code
F2.3 else, elif and Boolean operators
Worked answer
9(a)(i)Choose three different data typesShort answer3F1.8 Data types and casting
9(a)(ii)Complete a linear search functionComplete the algorithm4F5.5 Linear search
F4.2 Parameters and return values
Worked answer
9(b)Trace an if, elseif, else algorithm that scores a javelin throwTrace table4F13.2 Trace tables
F2.3 else, elif and Boolean operators
F5.4 Trace tables
Worked answer
9(c)A range check that outputs VALID or NOT VALID, and its test dataWrite a program7F6.1 Defensive design and validation
F6.3 Testing and test data
Worked answer
9(d)Complete an SQL statement with WHERESQL4F7.3 SQL: SELECT
F7.2 Relational databases
Worked answer
9(e)Abstraction and decomposition in the design of a programShort answer2F4.4 Decomposition and abstraction
9(f)Take teams and scores until stop, then output the winnerWrite a program6F2.7 Loop patterns
F2.6 Condition-controlled loops: while
F13.4 Programming questions
Worked answer

June 2023, Paper 2 (J277/02)

Sat 25 May 2023, 80 marks. On OCR's site: question paper, mark scheme.

QuestionWhat it testsTypeMarksLearn it
1(a)High-level and low-level languagesShort answer4F6.5 Languages and translators
1(b) to (d)An assignment, the arithmetic operators, and a do until trace tableTrace table7F1.9 Arithmetic operators
F5.4 Trace tables
F13.2 Trace tables
Worked answer
2Syntax and logic errors: correct a loop that should total an arrayFix the code6F6.4 Debugging logic errors
F3.4 Iterating over a list
F1.4 Errors: syntax, runtime and logic
Worked answer
3Insertion sort: temp, the inner loop, and bubble sort comparedExplain8F5.8 Insertion sort
F5.7 Bubble sort
Worked answer
4Draw a logic diagram and name gates from their truth tablesShort answer5F9.1 Logic gates and truth tables
F9.2 Logic circuits and expressions
5(a)Why programs are tested, a type of test, two features of an IDEShort answer8F6.3 Testing and test data
F6.6 The IDE
5(b)Two validation methods and how a game would use themExplain6F6.1 Defensive design and validation
5(c)An adding game: three random questions and a scoreWrite a program6F3.7 Random numbers
F2.5 Count-controlled loops: for
F13.4 Programming questions
Worked answer
6(a)Choose the data type for four variablesShort answer4F1.8 Data types and casting
6(b)Sound an alarm when armed AND (door OR window)Write a program4F2.3 else, elif and Boolean operators
F2.4 Nested selection and match
Worked answer
6(c)Find the concatenation, a variable, a function call and the constructsRead the code6F3.1 String handling
F4.2 Parameters and return values
F1.3 Calling functions
Worked answer
6(d)An SQL SELECT with two conditionsSQL3F7.3 SQL: SELECT
F7.2 Relational databases
Worked answer
6(e)A procedure with two parameters that writes to a text fileWrite a program6F7.1 Reading and writing files
F4.1 Writing functions
F4.2 Parameters and return values
Worked answer
6(f)Casting, and totalling a column of a 2D array for one dateWrite a program7F3.5 Two-dimensional arrays
F1.8 Data types and casting
F13.4 Programming questions
Worked answer

June 2022, Paper 2 (J277/02)

Sat 27 May 2022, 80 marks. On OCR's site: question paper, mark scheme.

QuestionWhat it testsTypeMarksLearn it
1Selection or iteration, incrementing a variable, decomposition and abstractionShort answer7F2.2 Selection: if
F2.5 Count-controlled loops: for
F4.4 Decomposition and abstraction
2(a)A logic diagram for (A OR B) AND NOT C, and what a truth table is forLogic6F9.1 Logic gates and truth tables
F9.2 Logic circuits and expressions
Worked answer
2(b)Design a flowchart that decides who gets a half-price mealWrite a program5F5.2 Flowcharts
F2.3 else, elif and Boolean operators
Worked answer
2(c)The extra inputs a change to the algorithm needsShort answer2F1.7 Input from the user
2(d)Casting, and a trace table for a while loop that pads a staff IDTrace table6F1.8 Data types and casting
F13.2 Trace tables
F2.6 Condition-controlled loops: while
Worked answer
3(a)Show each step of a merge sort on eight numbersExplain3F5.9 Merge sort and comparing algorithmsWorked answer
3(b), (c)Describe a binary search, and a linear search for a number that is not thereExplain6F5.6 Binary search
F5.5 Linear search
Worked answer
4(a), (b)Maintainability, arithmetic operators, and translatorsShort answer9F1.5 Comments and readable code
F1.9 Arithmetic operators
F6.5 Languages and translators
4(c)Input n numbers, then output the total and the averageWrite a program6F2.7 Loop patterns
F2.5 Count-controlled loops: for
F13.4 Programming questions
Worked answer
5(a)(i), (ii)Data types for the fields of a bookingShort answer3F1.8 Data types and casting
5(a)(iii)Correct an SQL statement: SELECT *, WHERE and the comparisonSQL4F7.3 SQL: SELECT
F7.2 Relational databases
Worked answer
5(b)Validate a booking with three checks, and plan the testsWrite a program8F6.1 Defensive design and validation
F6.3 Testing and test data
F2.3 else, elif and Boolean operators
Worked answer
5(c)Write a function that returns a price, then call itWrite a program7F4.1 Writing functions
F4.2 Parameters and return values
Worked answer
5(d)Two logic errors in a loop that totals an arrayFix the code2F6.4 Debugging logic errors
F3.4 Iterating over a list
Worked answer
5(e)Car park charges, repeated until 0 hours is enteredWrite a program6F2.6 Condition-controlled loops: while
F2.2 Selection: if
F13.4 Programming questions
Worked answer

Sample assessment material, Paper 2 (J277/02)

80 marks. On OCR's site: question paper, mark scheme.

QuestionWhat it testsTypeMarksLearn it
1A truth table and logic diagram for NOT(A AND B)Logic3F9.1 Logic gates and truth tables
F9.2 Logic circuits and expressions
2Complete a comparison of two numbers, then write a loop that doubles inputsWrite a program10F2.2 Selection: if
F2.6 Condition-controlled loops: while
Worked answer
3An SQL query for the students who take ArtSQL3F7.3 SQL: SELECT
4Usernames from a flowchart, then an algorithm for teachers and studentsWrite a program8F3.1 String handling
F5.2 Flowcharts
F2.2 Selection: if
Worked answer
5Why code is translated, and compilers against interpretersShort answer5F6.5 Languages and translators
6Show a bubble sort on words and a binary search for zebraExplain8F5.7 Bubble sort
F5.6 Binary search
Worked answer
7Maintainability, variables, constants, constructs and IDE features in a circle area programRead the code13F1.5 Comments and readable code
F1.6 Variables, constants and assignment
F6.6 The IDE
8(a)Choose a data type for minutes played and justify itShort answer2F1.8 Data types and casting
8(b) to (d)A range check with OR and its tests, index a 2D array, refine repeated lines into a loopWrite a program10F6.1 Defensive design and validation
F3.5 Two-dimensional arrays
F2.5 Count-controlled loops: for
Worked answer
8(e), (g)A while loop trace table, a function that returns minutes, and a flowchart as codeTrace table14F13.2 Trace tables
F4.2 Parameters and return values
F5.2 Flowcharts
Worked answer
8(f)Two pieces of test data for a length check and their outputsTesting4F6.3 Testing and test data

The specification

OCR GCSE Computer Science (J277), point by point, with the lesson for each section.

These are our own explanations of published exam questions. It is not written or endorsed by OCR, and the question paper and mark scheme remain OCR's copyright. Read them on OCR's site with the links on this page.