Structured programming and subroutines (procedures and functions)

EasyMediumHard
123456789101112131415161718192021222324252627282930313233343536373839404142
Question 22
Easy

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]

Structured programming and subroutines (procedures and functions) Questions

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