Check your understanding of the previous reading: the Ghost Hunt program.
In the Ghost Hunt program, there are six functions that are used to handle the grid (a list of lists of Tiles). These functions were either mutable or immutable, depending on whether they changed the grid or not. Note that just because a function returns a new grid does not mean it is mutable; a function is only mutable if it modifies the grid that was passed into it.
Which of the following grid functions were mutable in that they modified the actual grid that was passed into the function?
Select every one that applies, then check.
make_ghost_grid doesn't even take a grid as a parameter: it builds one from scratch with make_empty_grid and returns it.add_treat_if_empty sets grid[y][x].text = TREAT directly on the grid it was given.len(grid) to know the size; it never assigns into the grid, only returns a list of positions.fill_in_board assigns grid[y][x].text = GHOST and calls add_treat_if_empty on the grid it was given.draw_grid only reads the grid's tiles to build a separate display list; it never assigns into the grid.The choose_ghost_spots function returns a list of list of integers. Which of the following is the best explanation of that data?
Select one answer, then check.
positions.append([xs.pop(), ys.pop()]) adds one [x, y] pair for one ghost, so there is one two-element inner list per ghost.choose_ghost_spots only builds a short list of [x, y] positions, one per ghost.[x, y] list per ghost.[xs.pop(), ys.pop()].Look up the shuffle function in the Python standard library. Which of the following best describes what it does?
Select one answer, then check.
shuffle returns None; it doesn't build and return a new list.random.shuffle reorders the list it is given in place and returns None, which is exactly why the code calls it as a statement, shuffle(xs), rather than assigning its result.sorted, not shuffle. Shuffling randomizes order; it doesn't sort.sorted(..., reverse=True), not shuffle.random.choice, which the program also imports but doesn't use for this part.shuffle does; the code gets that removal effect separately, with .pop().The grid in this project is represented as a list of list of Tile objects. In some places, we access the grid using expressions like grid[y][x] (e.g., in fill_in_board and flip_tile). Why do we use grid[y][x] instead of grid[x][y]?
Select one answer, then check.
make_empty_grid builds the grid by looping for y in range(size) on the outside and for x in range(size) on the inside, appending each row before appending it to the grid, so the first index picks a row (y) and the second picks a column within it (x).make_empty_grid loops over y for the outer list and x for the inner one.Tile objects, not raw coordinates.In the State of this application, we have a field named score that keeps track of the player's score. Which of these best describes how the score field is updated during the game?
Select one answer, then check.
flip_tile only increments score inside the if tile.text == GHOST: check, not on every flip.score only ever goes up, via state.score += 1.flip_tile runs if tile.text == GHOST: state.score += 1, so only flipping a ghost tile raises the score.score unchanged; it never decreases.State or in the routes; the game has no time component.