Data structures · A level · OCR H446 1.4.2, AQA 7517 4.2.1.1, Eduqas A500QS 1.1 · about 20 min
Arrays in one, two and three dimensions, records and fields, tuples and lists, and static structures.
[1 mark]Which of these describes an array?
[1 mark]What does this program print?
scans = [[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]] print(len(scans), len(scans[0]), len(scans[0][0])) print(scans[2][0][1])
[1 mark]A two-dimensional array with 8 columns is stored in row-major order, starting at position 0. At what position is element [3][5]?
[1 mark]BugBot's position() returns a tuple rather than a list. Which is the best reason?
[1 mark]What does this program print?
grid = [[0] * 2] * 3 grid[1][0] = 7 print(grid)
[1 mark]Which of these are true of a record?
Tick every answer that is true.
scans is a 3D array of three saved 4 by 4 depth scans, indexed scans[scan][row][col], each value a whole number of centimetres from 1 to 100. Using nested loops and len(), print:
1. size: 3 x 4 x 4, working the three sizes out with len().
2. For each scan s from 0 to 2, scan <s> average: <mean>, the mean of its 16 values rounded to 1 decimal place with round(value, 1), for example scan 0 average: 56.0.
3. nearest: <cm> cm at [<scan>][<row>][<col>], the smallest value and its three indexes. The smallest value appears only once.
The robot does not move.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
# scans[scan][row][col]: three saved 4 by 4 depth scans, in cm
scans = [
[[45, 44, 43, 50], [40, 38, 39, 41], [60, 58, 57, 59], [80, 79, 81, 82]],
[[44, 42, 41, 49], [39, 36, 12, 40], [61, 57, 56, 60], [78, 80, 80, 83]],
[[46, 43, 42, 51], [41, 37, 38, 42], [59, 59, 55, 58], [81, 78, 82, 80]],
]Plan your program here, then type it in and press Run.
scans[2][1][3]? Check your answer by flattening the array into a 1D list.Reading as a tuple instead of a dataclass. What can you no longer do, and when would that be an advantage?