iGCSE Computer Science - Distance Learning

Tutor Marked Assignment 6
Tutor Marked Assignment 8 (Programming)

Using 2D Arrays in Programming (2023 Specification Only)

We’ve already looked at how data structures (arrays) are used to save data in a single dimension. When data is saved as a 1D array, this is often referred to as a list. When related data can be saved in lists, sometimes 1D arrays are used in parallel to create a digital table. This method is even more efficient when a table is created using a 2D array.

As we are using Python to create 2D arrays, there are several things that it is important to be aware of:

This is not a “true” array.

Python actually creates a matrix as a 2D data structure which is an array of arrays. A True 2D array will save rows and columns. This is why the syntax to read from the array looks different in python and pseudocode.

Look at the two examples below:


myTable = [[0,1,2],

print (myTable[1][1])

myTable <-- [[0,1,2],

OUTPUT myTable[1,1]

In the second example, the data is treated as if it has mathematical co-ordinates. This means that we identify the row, then the column separated by a comma (along the corridor & up the stairs)

Practice Task

The code shown in the video is a useful program to help you to read & write to 2D arrays. Try this yourself using the practice code below (this is not part of your assignment).

Assignment Task

Complete your tutor marked assignment for programming with this programming task which includes both reading from and writing to a 2D array.

The code below is practice code – please submit your final coded answer using the Tutor Marked Assignment Trinket pages.