Skip to content

Course home

Structured programming and subroutines (procedures and functions)

Structured programming and subroutines (procedures and functions)

EasyMediumHard
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
Question 21

An automated cargo system operates on a 3x3 distribution grid of shipping containers. Each cell contains a container of a specific weight (in tons) from 1 to 9, with one empty bay represented by 0.

The subroutines available for managing the grid are described in the table below:

SubroutinePurpose
getWeight(row, column)Returns the weight of the container on the grid at position (row, column). The value 0 represents the empty bay.
shift(row, column)Shifts the container at (row, column) into the adjacent empty bay, if the empty bay is directly next to it (horizontally or vertically).

Initial Grid State

Column 0Column 1Column 2
Row 0491
Row 1057
Row 2328

Program of Instructions

if getWeight(1, 0) == 0:
    shift(0, 0)

if getWeight(0, 0) == 0:
    shift(0, 1)

Complete the table below to show the final state of the grid after the program has run.

Column 0Column 1Column 2
Row 0
Row 1
Row 2
[2]
Markscheme

Structured programming and subroutines (procedures and functions) Questions

  1. GCSE
  2. /Computer Science
  3. /Structured programming and subroutines (procedures and functions)

131 exam-style questions on AQA GCSE Computer Science Structured programming and subroutines (procedures and functions). Each one has a worked solution and a mark scheme showing where the marks go.

Question bank