Predict

The Edge of the World

Before Pip takes a step, the game checks that the new position is still inside the map. Rows go from 0 to len(world) - 1, and columns from 0 to len(world[0]) - 1.

Python lets you chain comparisons: 0 <= row < 3 means "row is at least 0 and less than 3".

world = [".....",
         ".....",
         "....."]

def inside(pos):
    row, col = pos
    return (0 <= row < len(world)
            and 0 <= col < len(world[0]))

print(inside((2, 4)), inside((3, 0)),
      inside((0, 5)), inside((-1, 1)))

The map has 3 rows and 5 columns. What does this program print?