How to Answer Trace Table Questions (OCR GCSE Computer Science): Revision Note

Exam code: J277

Robert Hampton

Written by: Robert Hampton

Reviewed by: James Woodhouse

Updated on

How do I answer an OCR GCSE (9-1) Computer Science trace table question?

What is a trace table?

  • Trace tables are used to follow the values of variables as a program runs

  • These questions test your ability to simulate code line by line and accurately record outputs

Examiner Tips and Tricks

  • You must read the code carefully and simulate it exactly as a computer would

  • Use a pencil and annotate each step

  • The most common mistake is skipping or misreading a line

What you need to know

  • You may be asked to complete a trace table, explain a trace table, or spot errors in output

  • These questions are normally worth 3–6 marks

  • Most commonly appear in questions involving iteration, selection, and arrays/lists

  • In most cases, the structure of the table is provided, your task is to complete the missing values

Command words to look out for

Command word

What it means

Complete

Fill in the table with correct values

State

Give the value/output/result (usually a single word or number)

Explain

Say why something happens or changes in the program

Identify

Spot where something goes wrong or doesn't match expectations

How to tackle a trace table question

Follow these steps to answer trace table questions accurately:

  1. Read the code carefully

    Understand what each line does

    Look out for loops, IF statements, and variable changes

  2. Use the trace table provided
    Use the headings and row count to guide how many iterations or steps are needed

  3. Work line by line
    Simulate the program in your head or on paper

    Update each variable after every change

  4. Watch out for variable resets
    Variables declared inside loops often reset every time, don’t carry the wrong value across iterations

  5. Show the final output clearly
    If you're asked for the output, make sure it’s written exactly as it would appear on screen

Worked example

Question

This algorithm calculates the number of points a student gets for the distance they throw in the javelin:

01 javelinThrow = input("Enter distance")
02 yearGroup = input("Enter year group")
03 if javelinThrow >= 20.0 then
04     score = 3
05 elseif javelinThrow >= 10.0 then
06     score = 2
07 else
08     score = 1
09 endif
10 if yearGroup != 11 then
11     score = score * 2
12 endif
13 print("The score is", score)

Complete the trace table for the algorithm when a student in year 10 throws a distance of 14.3

You may not need to use all the rows in the table

Line number

javelinThrow

yearGroup

score

Output

  1. Read the code carefully

  • Line 1: It asks you to type in the javelin distance and stores it in a variable called javelinThrow

  • Line 2: It asks for your year group (like "10" or "11") and stores it in yearGroup

  • Lines 3–9: It decides how many points to give you:

    • If your throw was 20 metres or more, you get 3 points

    • If your throw was 10 metres or more, you get 2 points

    • If your throw was less than 10 metres, you get 1 point

  • Lines 10–12: It checks if you are not in Year 11:

    • If you're not in Year 11, your score is doubled

    • If you are in Year 11, your score stays the same

  • Line 13: It prints your final score

  1. Use the trace table provided

  • The trace table contains six blank lines which give you an indication of how many times a change/output is required

  • If you get to the end and you have only completed 2/3 lines, check again, something is probably wrong

  1. Work line by line

01 javelinThrow = input("Enter distance")

14.3

02 yearGroup = input("Enter year group")

10

03 if javelinThrow >= 20.0 then

No

04     score = 3
05 elseif javelinThrow >= 10.0 then

Yes

06     score = 2

score = 2

  1. Watch out for variable resets

  • This program contains no loops

  1. Show the final output clearly

13 print("The score is", score)

The score is 4

Final answer

Table with columns: Line number, javelinThrow, yearGroup, score, Output. Data includes scores of 2, 4, and a message "The score is 4".

Unlock more, it's free!

Join the 100,000+ Students that ❤️ Save My Exams

the (exam) results speak for themselves:

Robert Hampton

Author: Robert Hampton

Expertise: Computer Science Content Creator

Rob has over 16 years' experience teaching Computer Science and ICT at KS3 & GCSE levels. Rob has demonstrated strong leadership as Head of Department since 2012 and previously supported teacher development as a Specialist Leader of Education, empowering departments to excel in Computer Science. Beyond his tech expertise, Robert embraces the virtual world as an avid gamer, conquering digital battlefields when he's not coding.

James Woodhouse

Reviewer: James Woodhouse

Expertise: Computer Science & English Subject Lead

James graduated from the University of Sunderland with a degree in ICT and Computing education. He has over 14 years of experience both teaching and leading in Computer Science, specialising in teaching GCSE and A-level. James has held various leadership roles, including Head of Computer Science and coordinator positions for Key Stage 3 and Key Stage 4. James has a keen interest in networking security and technologies aimed at preventing security breaches.