Exercise 5 · Chapter: Your First FrameRequired+50 XP
A Solid Block
One loop draws a line. A loop inside a loop draws a shape.
Paint a solid gold rectangle covering rows 4 to 7 and columns 10 to 19.
That is 4 rows of 10 squares — 40 squares, from about five lines of code. This is the moment loops start paying you back.
Watch your range ends. range(4, 8) gives you 4, 5, 6, 7 — it stops before
the 8. You met that rule in For Loops, and it bites here too.
Expected output
........................................ ........................................ ........................................ ........................................ ..........AAAAAAAAAA.................... ..........AAAAAAAAAA.................... ..........AAAAAAAAAA.................... ..........AAAAAAAAAA.................... ........................................ ........................................ ........................................ ........................................ ........................................ ########################################
Need a hint?
3 available · costs 5 XP each
python
def draw(state):
grid = blank_grid()
# Two loops: rows 4 to 7 on the outside, columns 10 to 19 inside.
return grid