Representing text with number codes

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

Representing text with number codes

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. How does a computer store the letter B?
A As a number code
B As a tiny picture of the letter
2. In a simple A=1 code, which number stands for the letter C?
A 3
B 4
3. In an A=1 code, the numbers 8 and 9 stand for which word?
A HI
B IH
4. Which statement about character codes is true?
A Only letters have codes, so symbols like ! do not
B Every letter and symbol has its own number code
5. What does the computer do with a character code when it shows text on the screen?
A It shows the number instead of the character
B It turns the number back into the character

Match the Pairs

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

Left columnRight column
1A=1, B=2, C=3 AThe word HI written as number codes, with H as 8 and I as 9
2HI = 8 9 BA simple code where each letter is stored as its place in the alphabet
3A computer stores the letter C as a number, then turns it back into a letter on screen CThe computer stores B as the number 2, not as a letter. The number is turned back into B when it is shown.
4A secret code swaps each letter for its number so others cannot read the message at a glance DC = 3
5In an A=1 code, D = 5 ED is the 4th letter, so it should be 4. The number 5 is the code for E.
6The computer stores the letter B as the letter 2 F3 1 20 = CAT

Definitions

character code

Fill in the Blanks

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

1.
A = 1, B = 2, C = _
2.
Code for CAB: 3, 1, _
3.
A number for a letter is a _________ code
4.
Stored number: 2 Shown on screen: _
5.
Secret code for DOG: D=4, O=15, G=_

Spot the Error

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

Question 1
A A = 1
B B = 2
C C = 4
D CAB is 3 1 2
Question 2
A word = CAB
B C becomes 3
C B becomes 2
D A becomes 2
E coded message: 3 1 2
Question 3
A In an A=1 code, A is 0
B B is 2
C C is 3
Question 4
A message: 8 9
B 8 is H
C 9 is J
D so the message says HI
Question 5
A letter = 'A'
B code = chr(letter)
C print(code)
D # prints 65

Answer Key

Representing text with number codes
Section A: Quick Questions
Q1
A — As a number code
Q2
A — 3
Q3
A — HI
Q4
B — Every letter and symbol has its own number code
Q5
B — It turns the number back into the character
Section B: Match the Pairs
Q1
A=1, B=2, C=3 → A simple code where each letter is stored as its place in the alphabet
Q2
HI = 8 9 → The word HI written as number codes, with H as 8 and I as 9
Q3
A computer stores the letter C as a number, then turns it back into a letter on screen → C = 3
Q4
A secret code swaps each letter for its number so others cannot read the message at a glance → 3 1 20 = CAT
Q5
In an A=1 code, D = 5 → D is the 4th letter, so it should be 4. The number 5 is the code for E.
Q6
The computer stores the letter B as the letter 2 → The computer stores B as the number 2, not as a letter. The number is turned back into B when it is shown.
Section C: Definitions
Q1
character code — A number the computer uses to stand for one letter or symbol. It stores the number, then turns it back into the character on screen. In one A=1 code, A is 1 and B is 2.
Section D: Fill in the Blanks
Q1
A = 1, B = 2, C = 3
Q2
Code for CAB: 3, 1, 2
Q3
A number for a letter is a character code
Q4
Stored number: 2 Shown on screen: B
Q5
Secret code for DOG: D=4, O=15, G=7
Section E: Spot the Error
Q1
C — In an A=1 code, C is the third letter, so C = 3, not 4.
Q2
D — In an A=1 code, A is the first letter, so A becomes 1. The number 2 is the code for B.
Q3
A — In an A=1 code, A is 1. Because B is 2 and C is 3, A cannot be 0.
Q4
C — In an A=1 code, 9 is the letter I (A=1 ... H=8, I=9). J would be 10. The message says HI, so 9 must be I.
Q5
B — ord() changes a letter into its number code. chr() changes a number into a letter. The line should be code = ord(letter).