ASCII codes for digits, spaces and punctuation

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

ASCII codes for digits, spaces and punctuation

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. What is the ASCII code of the character '5'?
A 5
B 53
2. Which range of ASCII codes is used for the digit characters '0' to '9'?
A 0 to 9
B 48 to 57
3. What is the ASCII code for a space?
A 32
B 0
4. A student types 7 on a keyboard in a text box. How does the computer first store it?
A As the text character '7' with code 55
B As the number 7 in binary 00000111
5. Which statement is true?
A The character '0' has ASCII code 48
B The character '0' has ASCII code 0

Match the Pairs

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

Left columnRight column
1'5' = 53 AA space is a character and has its own ASCII code, 32
2' ' = 32 BThe text character '5' is stored with ASCII code 53, not the number 5
3The digit characters '0' to '9' use the ASCII codes 48 to 57 CThe character '7' has ASCII code 55, not 7. The code is not the same as the number's value.
4A typed number such as 42 is stored as text, one character code per digit D'0' = 48, '9' = 57
5'7' = 7 EA space is not code 0. The space character has ASCII code 32.
6' ' = 0 F'4' = 52, '2' = 50

Definitions

'5' = 53

Fill in the Blanks

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

1.
=____("5")
2.
=CHAR(__)
3.
=CODE("0")+_
4.
=CODE("5")=__
5.
="A"&____(32)&"B"

Spot the Error

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

Question 1
A digit = '7'
B code = ord(digit)
C print(code)
D print(code - 32)
Question 2
A a = '4'
B b = ' '
C print(ord(a))
D print(ord(b) == 0)
Question 3
A age = input('Age? ')
B # the user types 15
C print(age + 1)
Question 4
A ch = '9'
B print(ord(ch) == 9)
C print(ord(' ') == 32)
Question 5
A num = 5
B txt = '5'
C print(ord(num) == 53)

Answer Key

ASCII codes for digits, spaces and punctuation
Section A: Quick Questions
Q1
B — 53
Q2
B — 48 to 57
Q3
A — 32
Q4
A — As the text character '7' with code 55
Q5
A — The character '0' has ASCII code 48
Section B: Match the Pairs
Q1
'5' = 53 → The text character '5' is stored with ASCII code 53, not the number 5
Q2
' ' = 32 → A space is a character and has its own ASCII code, 32
Q3
The digit characters '0' to '9' use the ASCII codes 48 to 57 → '0' = 48, '9' = 57
Q4
A typed number such as 42 is stored as text, one character code per digit → '4' = 52, '2' = 50
Q5
'7' = 7 → The character '7' has ASCII code 55, not 7. The code is not the same as the number's value.
Q6
' ' = 0 → A space is not code 0. The space character has ASCII code 32.
Section C: Definitions
Q1
'5' = 53 — The text character '5' has ASCII code 53, not 5. Digits '0' to '9' are codes 48 to 57 and a space is 32, so a typed number is stored as text.
Section D: Fill in the Blanks
Q1
=CODE("5")
Q2
=CHAR(32)
Q3
=CODE("0")+9
Q4
=CODE("5")=53
Q5
="A"&CHAR(32)&"B"
Section E: Spot the Error
Q1
D — The code for '7' is 55. To get the number 7 you subtract 48, the code for '0', not 32, which is the code for a space.
Q2
D — A space is a character with ASCII code 32, so the check must be ord(b) == 32. Code 0 is not a space.
Q3
C — input() gives text, so age holds the characters '1' and '5'. Adding the number 1 to text causes an error. Join text with text: age + '1'.
Q4
B — The character '9' has ASCII code 57, not 9. The digits '0' to '9' are codes 48 to 57.
Q5
C — ord() works on a text character. num is the number 5, not the character '5'. Use txt, whose character '5' has code 53.