Telling literals of each type apart

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

Telling literals of each type apart

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which data type is the literal 7?
A INTEGER
B REAL
2. Which data type is the literal 7.0?
A INTEGER
B REAL
3. Which literal is a CHAR?
A '7'
B "7"
4. Which data type is the literal "7"?
A CHAR
B STRING
5. Which literal is a BOOLEAN?
A TRUE
B "TRUE"

Match the Pairs

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

Left columnRight column
17.0 A"7"
2'7' B"TRUE" in double quotes is a STRING, not a BOOLEAN. It should be written as TRUE with no quotes.
3Double quotes around the characters make a STRING literal, even when they look like a number CA REAL literal, because it is written with a decimal point
4TRUE written with no quotes is a BOOLEAN literal DTRUE
5Flag ← "TRUE" // Flag is BOOLEAN EA CHAR literal, because it is in single quotes
6Grade ← "A" // Grade is CHAR F"A" in double quotes is a STRING. A CHAR literal needs single quotes, so it should be 'A'.

Definitions

7 7.0 '7' "7" TRUE

Fill in the Blanks

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

1.
DECLARE Count : _______ Count ← 7
2.
DECLARE Price : ____ Price ← 7.0
3.
DECLARE Letter : ____ Letter ← '7'
4.
DECLARE Word : ______ Word ← "TRUE"
5.
DECLARE Done : _______ Done ← TRUE

Spot the Error

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

Question 1
A DECLARE Age : INTEGER
B Age ← 15.0
C OUTPUT Age
Question 2
A CONSTANT Pi ← "3.14"
B DECLARE Radius : REAL
C Radius ← 2.5
Question 3
A CONSTANT IsOpen ← "TRUE"
B DECLARE Msg : STRING
C Msg ← "Open"
Question 4
A DECLARE Letter : CHAR
B DECLARE Word : STRING
C Letter ← "Q"
D Word ← "Quiz"
Question 5
A DECLARE Price : REAL
B DECLARE Qty : INTEGER
C Qty ← 3
D Price ← '2.50'

Answer Key

Telling literals of each type apart
Section A: Quick Questions
Q1
A — INTEGER
Q2
B — REAL
Q3
A — '7'
Q4
B — STRING
Q5
A — TRUE
Section B: Match the Pairs
Q1
7.0 → A REAL literal, because it is written with a decimal point
Q2
'7' → A CHAR literal, because it is in single quotes
Q3
Double quotes around the characters make a STRING literal, even when they look like a number → "7"
Q4
TRUE written with no quotes is a BOOLEAN literal → TRUE
Q5
Flag ← "TRUE" // Flag is BOOLEAN → "TRUE" in double quotes is a STRING, not a BOOLEAN. It should be written as TRUE with no quotes.
Q6
Grade ← "A" // Grade is CHAR → "A" in double quotes is a STRING. A CHAR literal needs single quotes, so it should be 'A'.
Section C: Definitions
Q1
7 7.0 '7' "7" TRUE — How a literal is written shows its type: digits = INTEGER, decimal point = REAL, single quotes = CHAR, double quotes = STRING, TRUE or FALSE = BOOLEAN.
Section D: Fill in the Blanks
Q1
DECLARE Count : INTEGER Count ← 7
Q2
DECLARE Price : REAL Price ← 7.0
Q3
DECLARE Letter : CHAR Letter ← '7'
Q4
DECLARE Word : STRING Word ← "TRUE"
Q5
DECLARE Done : BOOLEAN Done ← TRUE
Section E: Spot the Error
Q1
B — 15.0 has a decimal point, so it is a REAL literal. Age is an INTEGER, so it needs a whole number written with digits only: Age ← 15.
Q2
A — Double quotes make "3.14" a STRING, not a number. Pi should be a REAL literal written with a decimal point and no quotes: CONSTANT Pi ← 3.14.
Q3
A — "TRUE" in double quotes is a STRING of four letters. The BOOLEAN literal is TRUE written with no quotes: CONSTANT IsOpen ← TRUE.
Q4
C — Double quotes make a STRING literal. A CHAR literal uses single quotes, so this should be Letter ← 'Q'.
Q5
D — Single quotes mean a CHAR, which holds only one character. A REAL literal has a decimal point and no quotes: Price ← 2.50.