Checkpoint

Checkpoint: The Case of the Twin Maps

Pip's map maker draws a sea and puts a square island on it. But instead of one island, a whole stripe of sand appears from top to bottom! And the island looks too thin.

The clue: [row] * 3 doesn't make three rows. It makes a list holding the same row three times.

grid = [[0] * 3] * 3
grid[0][0] = 9
print(grid)   # [[9, 0, 0], [9, 0, 0], [9, 0, 0]]
print(grid[0] is grid[1])   # True: twins!

A list comprehension runs [0] * 3 once per row, so each row is new: [[0] * 3 for _ in range(3)].

Assignment

Fix the two bugs, one from each family:

  1. make_grid(width, height, fill) must build height separate rows, each holding width copies of fill.
  2. mark_island(grid, x, y, size) must paint a full size by size square of "sand", with its top-left corner at column x, row y.

The picture should show a 3 by 3 island in the sea.