Bug hunt
The Sideways Flag
The Guild flag has two bands: the top colour fills the first
canvas.height // 2 rows, and the bottom colour fills the
rest. (// divides and throws away the remainder, so 7 // 2 is 3.)
Pip wrote draw_flag, but it misbehaves:
- On the 10 × 6 flag it crashes with
IndexError: (0, 6) is off the canvas. - On a square canvas it doesn't crash, but the bands stand up sideways, and the top band is one row (or column) too thick.
Two classic pixel bugs hide here:
- Swapped coordinates.
setalways wantsx(column) first, theny(row). Mixing them up flips the picture on its side. - Off by one. Rows
0tohalf - 1makehalfrows.<=would include rowhalftoo.
Pip tip: When a picture comes out sideways, check the order of
xandyfirst. It is the most common pixel bug of all.
Assignment
Fix draw_flag(canvas, top, bottom) so that:
- Rows
0up to (not including)canvas.height // 2aretop. - All other rows are
bottom. - It works on canvases of any width and height.
Fix draw_flag(canvas, top, bottom) so that:
- Rows
0up to (not including)canvas.height // 2aretop. - All other rows are
bottom. - It works on canvases of any width and height.
main.py Python sleeping
Press Run to try your code, then Check to test it.