Year 9 · Quiz 1

Two-dimensional arrays

10 multiple-choice questions on grids, grid[row][col], nested loops, counting, totaling and max on 2D data. Matches Parts 1–2 and 4–6 of the Year 9 Python tutorial.

Predict output Fill blanks Find errors
Fill in the blank

Question 1

In Python, a 2D array is usually built as a ___.

Choose one answer
Indexing order

Question 2

For grid[row][col], which index comes first?

Choose one answer
Predict the output

Question 3

What is printed?

grid = [
    [4, 7, 2, 9],
    [1, 5, 8, 3],
    [6, 0, 4, 2]
]
print(grid[0][0])
print(grid[1][2])
Choose one answer
Fill in the blank

Question 4

Number of rows and columns:

rows = len(grid)
cols = len(grid[___])
Choose one answer
Predict the output

Question 5

grid = [[4, 7], [1, 5], [6, 0]]
grid[2][1] = 10
print(grid[2][1])
Choose one answer
Nested loops

Question 6

Which pair of loops visits every cell in a rectangular grid?

Choose one answer
Predict the output

Question 7

How many cells are 5 or more?

grid = [[4, 7, 2], [1, 5, 8], [6, 0, 4]]
count = 0
for row in grid:
    for value in row:
        if value >= 5:
            count = count + 1
print(count)
Choose one answer
Predict the output

Question 8

What is the total of the whole grid?

grid = [[4, 7], [1, 5]]
total = 0
for row in grid:
    for value in row:
        total = total + value
print(total)
Choose one answer
Row and column totals

Question 9

For grid = [[4, 7, 2, 9], [1, 5, 8, 3], [6, 0, 4, 2]], what is column 2’s total (2 + 8 + 4)?

Choose one answer
Find the error / max

Question 10

What is the maximum value?

grid = [[4, 7, 2, 9], [1, 5, 8, 3], [6, 0, 4, 2]]
biggest = grid[0][0]
for row in grid:
    for value in row:
        if value > biggest:
            biggest = value
print(biggest)
Choose one answer

Back to Year 9 Python · Next: Quiz 2