Exerpad
🔥 0
0 XP
Exercise 2 · Chapter: Many at OnceRequired+50 XP

All of Them Fall

Now move every drop down by one, every frame.

The test prints the whole list each frame, so you'll see [1, 4, 7], then [2, 5, 8] — all three numbers climbing together.

Careful with this one:

for drop in state["drops"]:
    drop = drop + 1

That runs without error and does nothing. drop is a copy. Change the list by its index instead, and the drops will actually move.

Expected output
[1, 4, 7] [2, 5, 8] [3, 6, 9]
Need a hint?
3 available · costs 5 XP each
python
def new_game():
return {"drops": [0, 3, 6]}


def update(state, keys):
for drop in state["drops"]:
drop = drop + 1 # this changes a copy — fix it
return state


def draw(state):
grid = blank_grid()
for i in range(len(state["drops"])):
grid[state["drops"][i]][8 + i * 10] = "aqua"
return grid