Decoding a colour-by-number grid

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Decoding a colour-by-number grid

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A colour key says 0 = white, 1 = blue, 2 = red. What colour is a square with the number 2?
A Red
B Blue
2. Which step is the right way to decode a number in a colour-by-number grid?
A Look up the number in the colour key, then colour the square
B Pick any colour you like for the square
3. Key: 0 = white, 1 = black. A row reads 1 0 1. Which row of squares does it make?
A black, white, black
B white, black, white
4. What do you do after you colour one square when decoding a grid?
A Stop, because the picture is finished
B Move on to the next number and look it up in the key
5. Key: 1 = green, 2 = yellow. The grid has a square with the number 3. What should you do?
A Colour it green because 3 is close to 2
B Check the key and notice that 3 is not in it

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1key = {0: white, 1: black, 2: red} Asquare = 7, key has only 0, 1, 2, so 7 has no colour
2row 1: 2 0 1 BLook up 2, then 0, then 1 in the key and colour three squares in that order
3To decode a square, find its number in the colour key and use the matching colour Csquare = 2, key says 2 = red, so colour it red
4If a number is not in the key, you cannot colour that square until you check the key again DThe square was coloured without checking the key. A 1 should be black, so the picture is rebuilt wrongly.
5key says 1 = black, but you colour a 1 square white EThe colours do not follow the key. With 0 = white and 1 = black, the row should be red, white, black.
6row 1: 2 0 1 coloured as red, black, white FA colour key that says which colour each number stands for

Definitions

decode

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
key: 0 = white, 1 = black, 2 = red square = 2 colour = lookup(___, square)
2.
key: 0 = white, 1 = blue, 2 = green number = 2 if number = 2 then colour ← _____
3.
key: 0 = white, 1 = black number = 5 if number ______ key then say("No colour")
4.
for each ______ in grid do look up square in key colour the square
5.
grid ← [[0, 1], [1, 2]] key ← {0: white, 1: black, 2: red} picture ← ______(grid, key)

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A key: 0=white 1=black 1=red
B square ← 2
C colour ← lookup(key, square)
Question 2
A key: 0=white 1=blue 2=green
B square ← 1
C colour ← square
D fill square with colour
Question 3
A key: 0=white 1=black 2=red
B for each square in key:
C look up number in key
D colour square to match
Question 4
A row ← 0 1 3
B key: 0=white 1=blue 2=red
C check 3 is in the key: yes
Question 5
A key: 0=white 1=black
B square ← 4
C if square is in key:
D show error, skip square

Answer Key

Decoding a colour-by-number grid
Section A: Quick Questions
Q1
A — Red
Q2
A — Look up the number in the colour key, then colour the square
Q3
A — black, white, black
Q4
B — Move on to the next number and look it up in the key
Q5
B — Check the key and notice that 3 is not in it
Section B: Match the Pairs
Q1
key = {0: white, 1: black, 2: red} → A colour key that says which colour each number stands for
Q2
row 1: 2 0 1 → Look up 2, then 0, then 1 in the key and colour three squares in that order
Q3
To decode a square, find its number in the colour key and use the matching colour → square = 2, key says 2 = red, so colour it red
Q4
If a number is not in the key, you cannot colour that square until you check the key again → square = 7, key has only 0, 1, 2, so 7 has no colour
Q5
key says 1 = black, but you colour a 1 square white → The square was coloured without checking the key. A 1 should be black, so the picture is rebuilt wrongly.
Q6
row 1: 2 0 1 coloured as red, black, white → The colours do not follow the key. With 0 = white and 1 = black, the row should be red, white, black.
Section C: Definitions
Q1
decode — To decode a grid of numbers, look up each number in the colour key, then colour that square the matching colour. Doing this for every square rebuilds the picture.
Section D: Fill in the Blanks
Q1
key: 0 = white, 1 = black, 2 = red square = 2 colour = lookup(key, square)
Q2
key: 0 = white, 1 = blue, 2 = green number = 2 if number = 2 then colour ← green
Q3
key: 0 = white, 1 = black number = 5 if number not in key then say("No colour")
Q4
for each square in grid do look up square in key colour the square
Q5
grid ← [[0, 1], [1, 2]] key ← {0: white, 1: black, 2: red} picture ← decode(grid, key)
Section E: Spot the Error
Q1
A — In a colour key, each number stands for only one colour. Here 1 is used for both black and red, so you could not decode a 1. The last entry should be 2=red.
Q2
C — The number in the grid is not the colour. You must look the number up in the key to find its colour. It should be colour ← lookup(key, square).
Q3
B — You decode by going through the squares of the grid, not the entries in the key. It should be for each square in row 1:.
Q4
B — The row has a 3, so the key needs an entry for 3. This key has 2 instead, so the check on line 3 would fail. It should be key: 0=white 1=blue 3=red.
Q5
C — The number 4 is not in the key, so the error should show when the number is NOT in the key. It should be if square is not in key:.