Basic data types in pseudocode

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

Basic data types in pseudocode

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which data type should store the number of students in a class, such as 28?
A INTEGER
B REAL
2. Which data type should store a price such as 3.75?
A INTEGER
B REAL
3. Which data type should store a single letter grade such as 'B'?
A CHAR
B STRING
4. Which data type should store a name such as "Amira"?
A STRING
B CHAR
5. Which data type should store a value that can only be TRUE or FALSE, such as whether a door is locked?
A STRING
B BOOLEAN

Match the Pairs

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

Left columnRight column
1DECLARE Age : INTEGER AIsPassed can only store TRUE or FALSE
2DECLARE IsPassed : BOOLEAN BAge can only store whole numbers, such as 15 or 42
3A phone number should be stored as text because it can start with 0 and is never used in calculations CCHAR holds only one character, but "Merit" is several characters. Grade should be declared as STRING, or the value should be a single character such as "M".
4A price such as 4.99 has a fractional part, so it needs the type for decimal numbers DINTEGER cannot store a number with a fractional part like 72.5. Score should be declared as REAL, or the value should be a whole number.
5DECLARE Grade : CHAR Grade ← "Merit" EDECLARE PhoneNumber : STRING
6DECLARE Score : INTEGER Score ← 72.5 FDECLARE Price : REAL

Definitions

INTEGER, REAL, CHAR, STRING, BOOLEAN

Fill in the Blanks

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

1.
DECLARE Age : _______ Age ← 15
2.
DECLARE Price : ____ Price ← 2.75
3.
DECLARE Grade : ____ Grade ← 'A'
4.
DECLARE PhoneNumber : ______ PhoneNumber ← "0123456789"
5.
DECLARE IsValid : _______ IsValid ← TRUE

Spot the Error

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

Question 1
A DECLARE Age : INTEGER
B DECLARE Phone : STRING
C Age ← 15.5
Question 2
A DECLARE Price : REAL
B Price ← "4.99"
C OUTPUT Price
Question 3
A DECLARE Grade : CHAR
B INPUT Grade
C Grade ← 'AB'
Question 4
A DECLARE Phone : INTEGER
B Phone ← "07700900123"
C OUTPUT Phone
Question 5
A DECLARE IsOpen : BOOLEAN
B DECLARE Count : INTEGER
C IsOpen ← "TRUE"

Answer Key

Basic data types in pseudocode
Section A: Quick Questions
Q1
A — INTEGER
Q2
B — REAL
Q3
A — CHAR
Q4
A — STRING
Q5
B — BOOLEAN
Section B: Match the Pairs
Q1
DECLARE Age : INTEGER → Age can only store whole numbers, such as 15 or 42
Q2
DECLARE IsPassed : BOOLEAN → IsPassed can only store TRUE or FALSE
Q3
A phone number should be stored as text because it can start with 0 and is never used in calculations → DECLARE PhoneNumber : STRING
Q4
A price such as 4.99 has a fractional part, so it needs the type for decimal numbers → DECLARE Price : REAL
Q5
DECLARE Grade : CHAR Grade ← "Merit" → CHAR holds only one character, but "Merit" is several characters. Grade should be declared as STRING, or the value should be a single character such as "M".
Q6
DECLARE Score : INTEGER Score ← 72.5 → INTEGER cannot store a number with a fractional part like 72.5. Score should be declared as REAL, or the value should be a whole number.
Section C: Definitions
Q1
INTEGER, REAL, CHAR, STRING, BOOLEAN — The five basic pseudocode data types: whole numbers, decimals, a single character, text of any length, and TRUE or FALSE. A phone number should be a STRING.
Section D: Fill in the Blanks
Q1
DECLARE Age : INTEGER Age ← 15
Q2
DECLARE Price : REAL Price ← 2.75
Q3
DECLARE Grade : CHAR Grade ← 'A'
Q4
DECLARE PhoneNumber : STRING PhoneNumber ← "0123456789"
Q5
DECLARE IsValid : BOOLEAN IsValid ← TRUE
Section E: Spot the Error
Q1
C — Age is an INTEGER, so it can only hold whole numbers. 15.5 has a fractional part. Use a whole number such as 15, or declare Age as REAL.
Q2
B — Price is a REAL, so it needs a number. Quotes make "4.99" a STRING. It should be Price ← 4.99.
Q3
C — A CHAR holds exactly one character. 'AB' is two characters. Use one character such as 'A', or declare Grade as STRING.
Q4
A — A phone number is not used for arithmetic and often starts with 0, which an INTEGER would lose. It should be declared as STRING.
Q5
C — A BOOLEAN holds the values TRUE or FALSE without quotes. "TRUE" in quotes is a STRING. It should be IsOpen ← TRUE.