Structured programming and subroutines (procedures and functions)

EasyMediumHard
123456789101112131415161718192021222324252627282930313233343536373839404142
Question 17
Easy

A Python program operates on a 3x3 automated warehouse storage grid containing cargo containers numbered from 1 to 8, with one empty bay represented by 0.

The subroutines available for controlling the automated system are described in the table below:

SubroutinePurpose
inspectBay(row, column)Returns the ID of the cargo container in the storage grid in position (row, column). The value 0 represents an empty bay.
shiftItem(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 Storage Grid State

Column 0Column 1Column 2
Row 0472
Row 1105
Row 2836

Program of Instructions

if inspectBay(1, 1) == 0:
    shiftItem(2, 1)

if inspectBay(2, 1) == 0:
    shiftItem(2, 2)

Complete the table below to show the final state of the storage 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)