Skip to content

Course home

Structured programming and subroutines (procedures and functions)

Structured programming and subroutines (procedures and functions)

EasyMediumHard
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
Question 43

A Python program operates on a 3x3 sliding puzzle grid. The grid consists of numbered tiles from 1 to 8, with one empty space represented by 0.

The subroutines available for the game are described in the table below:

SubroutinePurpose
getTile(row, column)Returns the number of the tile on the board in position (row, column). The value 0 represents the empty space.
slide(row, column)Moves the tile at (row, column) into the adjacent empty space, if the empty space is directly next to it (horizontally or vertically).

Initial Board State

Column 0Column 1Column 2
Row 0503
Row 1284
Row 2176

Program of Instructions

if getTile(0, 1) == 0:
    slide(1, 1)

if getTile(1, 1) == 0:
    slide(1, 2)

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