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.
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
- June 2025 Paper 2, Question 5(d): Validate a 4 character PIN that must not be 1234 or 4321 (6 marks)
- June 2025 Paper 2, Question 6(a): Input two passwords and check that they match (4 marks)
- June 2025 Paper 2, Question 6(c): Write a function that returns a ticket price, then call it (6 marks)
- June 2025 Paper 2, Question 6(e): Sell tickets in a loop until none are left (6 marks)
- June 2024 Paper 2, Question 8: Maintainability, and a function that moves a character and keeps it in range (10 marks)
- June 2024 Paper 2, Question 9(c): A range check that outputs VALID or NOT VALID, and its test data (7 marks)
- June 2024 Paper 2, Question 9(f): Take teams and scores until stop, then output the winner (6 marks)
- June 2023 Paper 2, Question 5(c): An adding game: three random questions and a score (6 marks)
- June 2023 Paper 2, Question 6(b): Sound an alarm when armed AND (door OR window) (4 marks)
- June 2023 Paper 2, Question 6(e): A procedure with two parameters that writes to a text file (6 marks)
- June 2023 Paper 2, Question 6(f): Casting, and totalling a column of a 2D array for one date (7 marks)
- June 2022 Paper 2, Question 2(b): Design a flowchart that decides who gets a half-price meal (5 marks)
- June 2022 Paper 2, Question 4(c): Input n numbers, then output the total and the average (6 marks)
- June 2022 Paper 2, Question 5(b): Validate a booking with three checks, and plan the tests (8 marks)
- June 2022 Paper 2, Question 5(c): Write a function that returns a price, then call it (7 marks)
- June 2022 Paper 2, Question 5(e): Car park charges, repeated until 0 hours is entered (6 marks)
- Sample Paper 2, Question 2: Complete a comparison of two numbers, then write a loop that doubles inputs (10 marks)
- Sample Paper 2, Question 4: Usernames from a flowchart, then an algorithm for teachers and students (8 marks)
- Sample Paper 2, Question 8(b) to (d): A range check with OR and its tests, index a 2D array, refine repeated lines into a loop (10 marks)
Explain
- June 2025 Paper 2, Question 3(a): Show the steps of a merge sort on eight numbers (4 marks)
- June 2024 Paper 2, Question 3(c): Show a binary search for 10, its pre-requisite, and name merge sort (5 marks)
- June 2023 Paper 2, Question 3: Insertion sort: temp, the inner loop, and bubble sort compared (8 marks)
- June 2022 Paper 2, Question 3(a): Show each step of a merge sort on eight numbers (3 marks)
- June 2022 Paper 2, Question 3(b), (c): Describe a binary search, and a linear search for a number that is not there (6 marks)
- Sample Paper 2, Question 6: Show a bubble sort on words and a binary search for zebra (8 marks)
Trace table
- June 2025 Paper 2, Question 6(d): Trace a loop that totals an array, then refine it (7 marks)
- June 2024 Paper 2, Question 9(b): Trace an if, elseif, else algorithm that scores a javelin throw (4 marks)
- June 2023 Paper 2, Question 1(b) to (d): An assignment, the arithmetic operators, and a do until trace table (7 marks)
- June 2022 Paper 2, Question 2(d): Casting, and a trace table for a while loop that pads a staff ID (6 marks)
- Sample Paper 2, Question 8(e), (g): A while loop trace table, a function that returns minutes, and a flowchart as code (14 marks)
SQL
- June 2025 Paper 2, Question 6(b): Correct four errors in an SQL statement, a record, and data types (7 marks)
- June 2024 Paper 2, Question 9(d): Complete an SQL statement with WHERE (4 marks)
- June 2023 Paper 2, Question 6(d): An SQL SELECT with two conditions (3 marks)
- June 2022 Paper 2, Question 5(a)(iii): Correct an SQL statement: SELECT *, WHERE and the comparison (4 marks)
Read the code
- June 2025 Paper 2, Question 2(a), (b): Count the passes of a flowchart loop, and describe the kinds of iteration (8 marks)
- June 2024 Paper 2, Question 6: String methods: upper, left, right with a cast, and concatenation (6 marks)
- June 2023 Paper 2, Question 6(c): Find the concatenation, a variable, a function call and the constructs (6 marks)
Complete the algorithm
- June 2025 Paper 2, Question 4: Complete an algorithm that reads numbers from a text file, and casting (6 marks)
- June 2024 Paper 2, Question 2: Complete a flowchart that decides odd or even with MOD (4 marks)
- June 2024 Paper 2, Question 9(a)(ii): Complete a linear search function (4 marks)
Logic
- June 2025 Paper 2, Question 5(a), (b): A logic circuit from a description, and the truth table for A AND B (5 marks)
- June 2024 Paper 2, Question 5: A truth table for (A AND B) OR C and a circuit for NOT A AND (B OR C) (7 marks)
- June 2022 Paper 2, Question 2(a): A logic diagram for (A OR B) AND NOT C, and what a truth table is for (6 marks)
Fix the code
- June 2024 Paper 2, Question 3(a), (b): Define a syntax error, then correct two logic errors in a range check (6 marks)
- June 2023 Paper 2, Question 2: Syntax and logic errors: correct a loop that should total an array (6 marks)
- June 2022 Paper 2, Question 5(d): Two logic errors in a loop that totals an array (2 marks)
Testing
- June 2025 Paper 2, Question 1: Normal, boundary and invalid test data, and a 1 to 100 range check (9 marks)
Paper by paper
June 2025, Paper 2 (J277/02)
Sat 20 May 2025, 80 marks. On OCR's site: question paper, mark scheme.
| Question | What it tests | Type | Marks | Learn it | |
|---|---|---|---|---|---|
| 1 | Normal, boundary and invalid test data, and a 1 to 100 range check | Testing | 9 | F6.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 iteration | Read the code | 8 | F5.2 Flowcharts F2.6 Condition-controlled loops: while F2.5 Count-controlled loops: for | Worked answer |
| 2(c) | Two tools of an IDE | Short answer | 4 | F6.6 The IDE | |
| 3(a) | Show the steps of a merge sort on eight numbers | Explain | 4 | F5.9 Merge sort and comparing algorithms | Worked answer |
| 3(b), (c) | Insertion sort, bubble sort, arrays, and naming a linear search | Short answer | 5 | F5.8 Insertion sort F5.7 Bubble sort F5.5 Linear search | |
| 4 | Complete an algorithm that reads numbers from a text file, and casting | Complete the algorithm | 6 | F7.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 B | Logic | 5 | F9.1 Logic gates and truth tables F9.2 Logic circuits and expressions | Worked answer |
| 5(c) | Match abstraction, decomposition and algorithmic thinking to examples | Short answer | 3 | F4.4 Decomposition and abstraction | |
| 5(d) | Validate a 4 character PIN that must not be 1234 or 4321 | Write a program | 6 | F6.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 match | Write a program | 4 | F1.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 types | SQL | 7 | F7.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 it | Write a program | 6 | F4.1 Writing functions F4.2 Parameters and return values | Worked answer |
| 6(d) | Trace a loop that totals an array, then refine it | Trace table | 7 | F13.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 left | Write a program | 6 | F2.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.
| Question | What it tests | Type | Marks | Learn it | |
|---|---|---|---|---|---|
| 1 | Match if, for and while to selection and iteration | Short answer | 3 | F2.2 Selection: if F2.5 Count-controlled loops: for | |
| 2 | Complete a flowchart that decides odd or even with MOD | Complete the algorithm | 4 | F5.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 check | Fix the code | 6 | F6.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 sort | Explain | 5 | F5.6 Binary search F5.9 Merge sort and comparing algorithms | Worked answer |
| 4 | Inputs and outputs of a video program, and defensive design | Short answer | 4 | F6.1 Defensive design and validation | |
| 5 | A truth table for (A AND B) OR C and a circuit for NOT A AND (B OR C) | Logic | 7 | F9.1 Logic gates and truth tables F9.2 Logic circuits and expressions | Worked answer |
| 6 | String methods: upper, left, right with a cast, and concatenation | Read the code | 6 | F3.1 String handling F1.8 Data types and casting | Worked answer |
| 7 | Why use a low-level language, and the benefits of a compiler | Short answer | 5 | F6.5 Languages and translators | |
| 8 | Maintainability, and a function that moves a character and keeps it in range | Write a program | 10 | F4.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 types | Short answer | 3 | F1.8 Data types and casting | |
| 9(a)(ii) | Complete a linear search function | Complete the algorithm | 4 | F5.5 Linear search F4.2 Parameters and return values | Worked answer |
| 9(b) | Trace an if, elseif, else algorithm that scores a javelin throw | Trace table | 4 | F13.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 data | Write a program | 7 | F6.1 Defensive design and validation F6.3 Testing and test data | Worked answer |
| 9(d) | Complete an SQL statement with WHERE | SQL | 4 | F7.3 SQL: SELECT F7.2 Relational databases | Worked answer |
| 9(e) | Abstraction and decomposition in the design of a program | Short answer | 2 | F4.4 Decomposition and abstraction | |
| 9(f) | Take teams and scores until stop, then output the winner | Write a program | 6 | F2.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.
| Question | What it tests | Type | Marks | Learn it | |
|---|---|---|---|---|---|
| 1(a) | High-level and low-level languages | Short answer | 4 | F6.5 Languages and translators | |
| 1(b) to (d) | An assignment, the arithmetic operators, and a do until trace table | Trace table | 7 | F1.9 Arithmetic operators F5.4 Trace tables F13.2 Trace tables | Worked answer |
| 2 | Syntax and logic errors: correct a loop that should total an array | Fix the code | 6 | F6.4 Debugging logic errors F3.4 Iterating over a list F1.4 Errors: syntax, runtime and logic | Worked answer |
| 3 | Insertion sort: temp, the inner loop, and bubble sort compared | Explain | 8 | F5.8 Insertion sort F5.7 Bubble sort | Worked answer |
| 4 | Draw a logic diagram and name gates from their truth tables | Short answer | 5 | F9.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 IDE | Short answer | 8 | F6.3 Testing and test data F6.6 The IDE | |
| 5(b) | Two validation methods and how a game would use them | Explain | 6 | F6.1 Defensive design and validation | |
| 5(c) | An adding game: three random questions and a score | Write a program | 6 | F3.7 Random numbers F2.5 Count-controlled loops: for F13.4 Programming questions | Worked answer |
| 6(a) | Choose the data type for four variables | Short answer | 4 | F1.8 Data types and casting | |
| 6(b) | Sound an alarm when armed AND (door OR window) | Write a program | 4 | F2.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 constructs | Read the code | 6 | F3.1 String handling F4.2 Parameters and return values F1.3 Calling functions | Worked answer |
| 6(d) | An SQL SELECT with two conditions | SQL | 3 | F7.3 SQL: SELECT F7.2 Relational databases | Worked answer |
| 6(e) | A procedure with two parameters that writes to a text file | Write a program | 6 | F7.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 date | Write a program | 7 | F3.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.
| Question | What it tests | Type | Marks | Learn it | |
|---|---|---|---|---|---|
| 1 | Selection or iteration, incrementing a variable, decomposition and abstraction | Short answer | 7 | F2.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 for | Logic | 6 | F9.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 meal | Write a program | 5 | F5.2 Flowcharts F2.3 else, elif and Boolean operators | Worked answer |
| 2(c) | The extra inputs a change to the algorithm needs | Short answer | 2 | F1.7 Input from the user | |
| 2(d) | Casting, and a trace table for a while loop that pads a staff ID | Trace table | 6 | F1.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 numbers | Explain | 3 | F5.9 Merge sort and comparing algorithms | Worked answer |
| 3(b), (c) | Describe a binary search, and a linear search for a number that is not there | Explain | 6 | F5.6 Binary search F5.5 Linear search | Worked answer |
| 4(a), (b) | Maintainability, arithmetic operators, and translators | Short answer | 9 | F1.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 average | Write a program | 6 | F2.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 booking | Short answer | 3 | F1.8 Data types and casting | |
| 5(a)(iii) | Correct an SQL statement: SELECT *, WHERE and the comparison | SQL | 4 | F7.3 SQL: SELECT F7.2 Relational databases | Worked answer |
| 5(b) | Validate a booking with three checks, and plan the tests | Write a program | 8 | F6.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 it | Write a program | 7 | F4.1 Writing functions F4.2 Parameters and return values | Worked answer |
| 5(d) | Two logic errors in a loop that totals an array | Fix the code | 2 | F6.4 Debugging logic errors F3.4 Iterating over a list | Worked answer |
| 5(e) | Car park charges, repeated until 0 hours is entered | Write a program | 6 | F2.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.
| Question | What it tests | Type | Marks | Learn it | |
|---|---|---|---|---|---|
| 1 | A truth table and logic diagram for NOT(A AND B) | Logic | 3 | F9.1 Logic gates and truth tables F9.2 Logic circuits and expressions | |
| 2 | Complete a comparison of two numbers, then write a loop that doubles inputs | Write a program | 10 | F2.2 Selection: if F2.6 Condition-controlled loops: while | Worked answer |
| 3 | An SQL query for the students who take Art | SQL | 3 | F7.3 SQL: SELECT | |
| 4 | Usernames from a flowchart, then an algorithm for teachers and students | Write a program | 8 | F3.1 String handling F5.2 Flowcharts F2.2 Selection: if | Worked answer |
| 5 | Why code is translated, and compilers against interpreters | Short answer | 5 | F6.5 Languages and translators | |
| 6 | Show a bubble sort on words and a binary search for zebra | Explain | 8 | F5.7 Bubble sort F5.6 Binary search | Worked answer |
| 7 | Maintainability, variables, constants, constructs and IDE features in a circle area program | Read the code | 13 | F1.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 it | Short answer | 2 | F1.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 loop | Write a program | 10 | F6.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 code | Trace table | 14 | F13.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 outputs | Testing | 4 | F6.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.