Community resourceWorksheet

J277 2.2.3 Two-dimensional arrays and records

Part 1 of 5 · J277 2.2.3 · Applied programming

Two-dimensional arrays and records, the two structures OCR uses for grids and for entities.

Students will:

  • create a two-dimensional structure and access it by row and column
  • update a value at a given grid position
  • process every value with nested loops
  • represent one entity as a record with named fields
  • choose between a grid and a record for a requirement

Inside: 6 explanation cells, 4 runnable Python tasks, 2 multiple-choice questions, 1 fill-in-the-blanks cell and 2 written answers. 23 marks, about 60 minutes.

Series: J277 2.2.3 · Applied programming, part 1 of 5.

Shared by Coding PathwayVerified teacher

  • 15 cells
  • About 60 minutes
  • CC BY-SA 4.0
  • Shared 17 Aug 2026
  • Updated 9 Sept 2026

Preview

The whole resource, exactly as a class sees it. Answers and marking are held back.

Two-dimensional arrays and records

A two-dimensional array organises elements into rows and columns. OCR treats arrays as fixed-length structures whose elements use the same data type. In Python we use a list containing lists to model a 2D array, while remembering that Python lists themselves can change size.

Python indices begin at 0, so the first index selects a row and the second selects a column within that row. A record groups related fields about one entity, such as one student, book or product. Every field has a name and a value, and different fields in a record may use different data types.

Multiple choice1 mark

Which expression selects the value in the second row and third column of a Python list named grid?

  • Agrid[1][2]
  • Bgrid[2][3]
  • Cgrid[2, 3]
  • Dgrid[1:2]

Rows, columns and nested loops

temperatures = [
    [12, 14, 13],
    [15, 16, 14]
]
A two-dimensional array compared with a record The two-dimensional array has numbered rows and columns and selects 13 using row 0, column 2. The record uses named fields book_id, title and on_loan, with values of different data types. Two-dimensional array positions are selected by row and column indices column 0column 1column 2 row 0row 1 1214 1315 1614 temperatures[0][2] = 13 One record named fields describe one entity book_id 417 integer title Orbit string on_loan False Boolean field name → value → data type

temperatures[0][2] is 13. The first index selects a row; the second selects an element in that row. A nested loop can process every cell, with the outer loop selecting rows and the inner loop selecting values.

A record is different: its fields can have different meanings and data types. One book record might contain an identifier, title and Boolean loan status.

A two-dimensional array can emulate a database table when every row represents one record and each column position represents the same field. For example, column 0 might always contain an identifier and column 2 might always contain a score. A record is preferable when named fields make the meaning of each value clearer.

Before running the example below, predict the first displayed name. Then trace the nested loops row by row and explain why all six names are displayed.

Worked example
seats = [
    ["Ava", "Ben", "Cara"],
    ["Dev", "Eli", "Faye"]
]
print(seats[1][2])
for row in seats:
    for name in row:
        print(name)
Fill in the blanks4 marks
Choose from the answer bank to complete the summary of two-dimensional arrays and records: A two-dimensional array is organised into label 1 and label 2. Selecting an element requires label 3 indices. A record groups related label 4 about one entity.
  • rows
  • columns
  • two
  • one
  • fields
  • files

Supported practice: select and update grid positions

The supplied 3 by 3 grid uses zero-based row and column indices. Store the centre value in centre, then change the bottom-right element from 0 to 9.

For the centre, both indices are 1. For the bottom-right position, both indices are 2. Use nested indexing rather than rebuilding the grid.

Coding task4 marks
grid = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 0]
]

# 1. Select and store the centre element.
# 2. Update the bottom-right element to 9.

Independent practice: process every grid value

Calculate the total of all six sales values. Use one loop to visit each row and a nested loop to visit each value within that row. Add every value to the accumulator total.

The expected total is 21. total = 0 and the empty running total are genuine parts of the accumulation pattern.

Coding task3 marks
# Calculate the total of every value in the two-dimensional array.
sales = [[3, 5, 2], [4, 1, 6]]
total = 0
# Use nested loops.

Worked example: representing one record

The next example switches from positional grid data to named fields describing one book. A Python dictionary is one way to represent an OCR record: each key is a field name and each associated value is that field's data.

Run the example, then identify the three field names, their data types and the field that changes.

Worked example
# A dictionary is one Python way to represent a record.
book = {
    "book_id": 417,
    "title": "Orbit",
    "on_loan": False
}
print(book["title"])
book["on_loan"] = True
Multiple choice1 mark

In a table of student records, what does one complete row normally represent?

  • AOne field name only
  • BOne complete student record
  • CEvery record in the file
  • DA two-dimensional index
Written answer6 marks

Design part of a record for one bicycle in a hire system. Give three suitable field names, one sensible example value for each field and the data type of each value.

Present three field–value–type combinations. Choose fields that describe one bicycle and use precise types such as integer, string, real or Boolean.

Students type their answer here.

Written answer4 marks

Explain how a two-dimensional array can emulate a database table, then give one important difference between an array row and a record with named fields.

Refer to what rows and columns represent, how a field is selected and the data types that may be stored.

Students type their answer here.

Review

Use two-dimensional arrays for fixed, regular row-and-column data accessed by position. In a table model, a row represents a record and each column position represents a field. Use records when named fields describe one entity and may hold different data types. In Python, nested lists model 2D arrays and dictionaries are one way to model named record fields.