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:

  1. Swapped coordinates. set always wants x (column) first, then y (row). Mixing them up flips the picture on its side.
  2. Off by one. Rows 0 to half - 1 make half rows. <= would include row half too.

Pip tip: When a picture comes out sideways, check the order of x and y first. It is the most common pixel bug of all.

Assignment

Fix draw_flag(canvas, top, bottom) so that:

  1. Rows 0 up to (not including) canvas.height // 2 are top.
  2. All other rows are bottom.
  3. It works on canvases of any width and height.