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

Back to the Top

Right now the drops fall out of the world and the next draw crashes.

Send each one back to the top instead. After moving a drop, if it has gone past the bottom row, set it to 0.

Now the rain never stops: three drops, endlessly recycled. Real rain animations work exactly like this — a handful of drops reused forever, not thousands created and destroyed.

If you spotted that % from Chapter 2 does the same job in one line, you're right, and either answer passes.

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


def update(state, keys):
for i in range(len(state["drops"])):
state["drops"][i] = state["drops"][i] + 1
# If this drop has fallen past the bottom, send it back to row 0.
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