Writing literals in Cambridge pseudocode

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

Writing literals in Cambridge pseudocode

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which is a correct REAL literal in Cambridge pseudocode?
A 4.7
B .7
2. Which is the correct way to write the CHAR literal x?
A "x"
B 'x'
3. Which is a correct STRING literal?
A 'Hello'
B "Hello"
4. Which is a correct BOOLEAN literal?
A TRUE
B "TRUE"
5. Which is a correct real literal for zero?
A 0.0
B 0.

Match the Pairs

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

Left columnRight column
1'x' AAn empty STRING literal: double quotes with no characters between them
2"" BA CHAR literal: a single character written inside single quotes
3A REAL literal must have a digit on each side of the decimal point CThe REAL literal has no digit before the decimal point. It should be written 0.5.
4A BOOLEAN literal is written as TRUE or FALSE, with no quote marks DPrice ← 0.0
5Letter ← "x" EA single CHAR is written in double quotes, which makes it a STRING. CHAR literals need single quotes: 'x'.
6Height ← .5 FFound ← TRUE

Definitions

literal

Fill in the Blanks

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

1.
DECLARE Total : REAL Total ← 0._
2.
DECLARE Initial : ____ Initial ← 'x'
3.
DECLARE Greeting : ______ Greeting ← "Hello"
4.
DECLARE Name : STRING ____ ← ""
5.
DECLARE Found : BOOLEAN Found ← _____

Spot the Error

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

Question 1
A DECLARE Price : REAL
B DECLARE Grade : CHAR
C Price ← 4.
D Grade ← 'A'
Question 2
A DECLARE Name : STRING
B DECLARE Score : REAL
C Name ← "Hello"
D Score ← .0
Question 3
A Letter ← 'xy'
B OUTPUT Letter
C OUTPUT "Done"
Question 4
A DECLARE Greeting : STRING
B Greeting ← "Hi"
C OUTPUT 'Hello'
D OUTPUT Greeting
Question 5
A DECLARE Found : BOOLEAN
B Found ← "FALSE"
C OUTPUT Found

Answer Key

Writing literals in Cambridge pseudocode
Section A: Quick Questions
Q1
A — 4.7
Q2
B — 'x'
Q3
B — "Hello"
Q4
A — TRUE
Q5
A — 0.0
Section B: Match the Pairs
Q1
'x' → A CHAR literal: a single character written inside single quotes
Q2
"" → An empty STRING literal: double quotes with no characters between them
Q3
A REAL literal must have a digit on each side of the decimal point → Price ← 0.0
Q4
A BOOLEAN literal is written as TRUE or FALSE, with no quote marks → Found ← TRUE
Q5
Letter ← "x" → A single CHAR is written in double quotes, which makes it a STRING. CHAR literals need single quotes: 'x'.
Q6
Height ← .5 → The REAL literal has no digit before the decimal point. It should be written 0.5.
Section C: Definitions
Q1
literal — A fixed value written in code: a real with digits either side of the point (4.7), a CHAR in single quotes ('x'), a STRING in double quotes ("Hello"), or BOOLEAN TRUE or FALSE.
Section D: Fill in the Blanks
Q1
DECLARE Total : REAL Total ← 0.0
Q2
DECLARE Initial : CHAR Initial ← 'x'
Q3
DECLARE Greeting : STRING Greeting ← "Hello"
Q4
DECLARE Name : STRING Name ← ""
Q5
DECLARE Found : BOOLEAN Found ← FALSE
Section E: Spot the Error
Q1
C — A REAL literal needs a digit on each side of the decimal point. It should be Price ← 4.7.
Q2
D — A REAL literal needs a digit before the decimal point as well as after it. It should be Score ← 0.0.
Q3
A — A CHAR literal is exactly one character in single quotes. 'xy' is two characters, so it should be 'x'.
Q4
C — A STRING literal uses double quotes. Single quotes are for a CHAR, so it should be OUTPUT "Hello".
Q5
B — A BOOLEAN literal is written as TRUE or FALSE with no quotes. In quotes it becomes a STRING. It should be Found ← FALSE.