Exercise 3 · Chapter: One Moving DotRequired+50 XP
Falling
Now drop something.
updateadds1tostate["y"]each framedrawpaints a blue square at rowstate["y"], column20
Notice what changed from the last exercise: the moving number is now the first index instead of the second. That is the entire difference between sideways and downwards.
Bigger y means further down, because row 0 is the top of the picture.
This trips up nearly everyone once.
Expected output
1 2 3 4 5
Need a hint?
3 available · costs 5 XP each
python
def update(state, keys):
# Add 1 to state["y"] so the dot moves down.
return state
def draw(state):
grid = blank_grid()
# Paint a blue square at row state["y"], column 20.
return grid