Data type keywords: INTEGER, REAL, CHAR, STRING, BOOLEAN

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

Data type keywords: INTEGER, REAL, CHAR, STRING, BOOLEAN

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which data type should a variable holding a student's age in whole years use?
A STRING
B INTEGER
2. Which data type suits a price such as 4.75?
A REAL
B INTEGER
3. Which data type is best for a phone number such as 07911123456?
A INTEGER
B STRING
4. Which data type holds exactly one letter, such as a grade 'B'?
A CHAR
B STRING
5. Which data type suits a postcode such as SW1A 2AA?
A STRING
B CHAR

Match the Pairs

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

Left columnRight column
1DECLARE Age : INTEGER ADECLARE PhoneNumber : STRING
2DECLARE Grade : CHAR BDECLARE Price : REAL
3A phone number or postcode must be stored as a STRING, because it can start with 0 and is never used in sums. CAge can hold only whole numbers, such as 15 or 42, with no fractional part.
4A price such as 3.75 has a fractional part, so it needs the REAL data type, not INTEGER. DA value that is only TRUE or FALSE should use the BOOLEAN data type, not STRING.
5DECLARE Postcode : INTEGER EA postcode can start with 0 or contain letters, and you never do sums with it. It should be a STRING, not an INTEGER.
6DECLARE IsLoggedIn : STRING FGrade holds exactly one character, such as 'A'.

Definitions

INTEGER, REAL, CHAR, STRING, BOOLEAN

Fill in the Blanks

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

1.
DECLARE Age : _______
2.
DECLARE Price : ____
3.
DECLARE Grade : ____
4.
DECLARE PhoneNumber : ______
5.
DECLARE IsValid : _______

Spot the Error

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

Question 1
A DECLARE Age : INTEGER
B DECLARE Price : REAL
C Price ← 2.50
D Age ← 15.5
Question 2
A DECLARE Initial : CHARACTER
B Initial ← 'K'
C OUTPUT Initial
Question 3
A // Store a phone number
B DECLARE Name : STRING
C INPUT Name
D DECLARE Phone : INTEGER
E INPUT Phone
Question 4
A DECLARE Passed : BOOLEAN
B Passed ← "TRUE"
C IF Passed = TRUE THEN
D OUTPUT "Well done"
E ENDIF
Question 5
A DECLARE Count : INTEGER
B DECLARE Height REAL
C Height ← 1.75

Answer Key

Data type keywords: INTEGER, REAL, CHAR, STRING, BOOLEAN
Section A: Quick Questions
Q1
B — INTEGER
Q2
A — REAL
Q3
B — STRING
Q4
A — CHAR
Q5
A — STRING
Section B: Match the Pairs
Q1
DECLARE Age : INTEGER → Age can hold only whole numbers, such as 15 or 42, with no fractional part.
Q2
DECLARE Grade : CHAR → Grade holds exactly one character, such as 'A'.
Q3
A phone number or postcode must be stored as a STRING, because it can start with 0 and is never used in sums. → DECLARE PhoneNumber : STRING
Q4
A price such as 3.75 has a fractional part, so it needs the REAL data type, not INTEGER. → DECLARE Price : REAL
Q5
DECLARE Postcode : INTEGER → A postcode can start with 0 or contain letters, and you never do sums with it. It should be a STRING, not an INTEGER.
Q6
DECLARE IsLoggedIn : STRING → A value that is only TRUE or FALSE should use the BOOLEAN data type, not STRING.
Section C: Definitions
Q1
INTEGER, REAL, CHAR, STRING, BOOLEAN — The five data types, in order: whole number, number with a fractional part, one character, zero or more characters, TRUE or FALSE. A phone number is a STRING.
Section D: Fill in the Blanks
Q1
DECLARE Age : INTEGER
Q2
DECLARE Price : REAL
Q3
DECLARE Grade : CHAR
Q4
DECLARE PhoneNumber : STRING
Q5
DECLARE IsValid : BOOLEAN
Section E: Spot the Error
Q1
D — Age is an INTEGER, so it can only hold a whole number. 15.5 has a fractional part. It should be a whole number such as 15, or Age should be declared as REAL.
Q2
A — The Cambridge keyword for a single character is CHAR, not CHARACTER. It should be DECLARE Initial : CHAR.
Q3
D — A phone number is not used for calculations and often starts with 0, which an INTEGER would drop. It must be a STRING, so: DECLARE Phone : STRING.
Q4
B — A BOOLEAN holds the value TRUE or FALSE, written without quotes. "TRUE" in quotes is a STRING. It should be Passed ← TRUE.
Q5
B — A declaration needs a colon between the identifier and the data type. It should be DECLARE Height : REAL.