STRING data type

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

STRING data type

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which is a valid STRING literal in Cambridge pseudocode?
A 'Hello World'
B "Hello World"
2. Which line correctly declares a variable to store a person's name?
A DECLARE Name : STRING
B DECLARE Name : TEXT
3. What is "" in pseudocode?
A The empty string, a STRING with zero characters
B An error, because a STRING must have at least one character
4. What is the data type of "123"?
A STRING, because it is in double quotes
B INTEGER, because it only contains digits
5. What is the data type of "A"?
A CHAR, because it is one character long
B STRING, because it uses double quotes

Match the Pairs

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

Left columnRight column
1DECLARE Name : STRING ACode ← "123"
2Text ← "" BCreates a variable that can store text made of zero or more characters
3A STRING literal is written between double quotes CGreeting ← "Hello, Sam"
4Digits inside double quotes are text, not a number, so they are a STRING DStores the empty string, which has zero characters, in Text
5Name ← Sam E"1234" is a STRING because of the double quotes, so it cannot be assigned to an INTEGER variable. Declare Pin as STRING or assign 1234.
6DECLARE Pin : INTEGER Pin ← "1234" FThe text has no double quotes, so it is not a STRING literal. It should be Name ← "Sam".

Definitions

STRING

Fill in the Blanks

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

1.
DECLARE UserName : ______
2.
DECLARE Message : STRING _______ ← ""
3.
DECLARE PhoneNumber : ______ PhoneNumber ← "0123456789"
4.
_______ Word : STRING Word ← "A"
5.
DECLARE Reply : STRING Reply _ "123"

Spot the Error

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

Question 1
A DECLARE Name : STRING
B Name ← "Ava"
C OUTPUT "Hi , Name
Question 2
A DECLARE Pet : TEXT
B Pet ← "Cat"
C OUTPUT Pet
Question 3
A DECLARE Pin : STRING
B Pin ← "1234"
C DECLARE Next : STRING
D Next ← 5678
Question 4
A DECLARE Name : STRING
B INPUT Name
C IF Name = "" THEN
D Name ← Guest
E ENDIF
Question 5
A DECLARE Age : INTEGER
B Age ← "15"
C OUTPUT Age + 1

Answer Key

STRING data type
Section A: Quick Questions
Q1
B — "Hello World"
Q2
A — DECLARE Name : STRING
Q3
A — The empty string, a STRING with zero characters
Q4
A — STRING, because it is in double quotes
Q5
B — STRING, because it uses double quotes
Section B: Match the Pairs
Q1
DECLARE Name : STRING → Creates a variable that can store text made of zero or more characters
Q2
Text ← "" → Stores the empty string, which has zero characters, in Text
Q3
A STRING literal is written between double quotes → Greeting ← "Hello, Sam"
Q4
Digits inside double quotes are text, not a number, so they are a STRING → Code ← "123"
Q5
Name ← Sam → The text has no double quotes, so it is not a STRING literal. It should be Name ← "Sam".
Q6
DECLARE Pin : INTEGER Pin ← "1234" → "1234" is a STRING because of the double quotes, so it cannot be assigned to an INTEGER variable. Declare Pin as STRING or assign 1234.
Section C: Definitions
Q1
STRING — The data type for text: zero or more characters written between double quotes, such as "This is a string". "" is the empty string and "123" is text, not a number.
Section D: Fill in the Blanks
Q1
DECLARE UserName : STRING
Q2
DECLARE Message : STRING Message ← ""
Q3
DECLARE PhoneNumber : STRING PhoneNumber ← "0123456789"
Q4
DECLARE Word : STRING Word ← "A"
Q5
DECLARE Reply : STRING Reply ← "123"
Section E: Spot the Error
Q1
C — A STRING literal must start and end with double quotes. The closing quote is missing after Hi. It should be OUTPUT "Hi ", Name.
Q2
A — TEXT is not a Cambridge pseudocode data type. The data type for text is STRING, so the line should be DECLARE Pet : STRING.
Q3
D — Next is a STRING variable, so it must be given text in double quotes. 5678 without quotes is an INTEGER. It should be Next ← "5678".
Q4
D — Text must be written in double quotes. Without them, Guest looks like an identifier, not a STRING value. It should be Name ← "Guest".
Q5
B — "15" in double quotes is a STRING, which is text and not a number. Age is an INTEGER, so it needs the number 15 with no quotes: Age ← 15.