Exerpad
🔥 0
0 XP
Exercise 4 · Chapter: One Moving DotRequired+50 XP

Diagonal

Move sideways and downwards at the same time and you get a diagonal. There is no "diagonal" feature — it falls out of doing both.

  • update adds 1 to both state["x"] and state["y"]
  • draw paints a gold square at grid[state["y"]][state["x"]]

The test prints both numbers each frame, separated by a slash, so you'll see them climb together: 1/1, then 2/2, and so on.

Expected output
1/1 2/2 3/3 4/4 5/5
Need a hint?
3 available · costs 5 XP each
python
def update(state, keys):
state["x"] = state["x"] + 1
# The dot only moves sideways. Make it move down too.
return state


def draw(state):
grid = blank_grid()
grid[state["y"]][state["x"]] = "gold"
return grid