A constant's value must be a literal

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

A constant's value must be a literal

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which constant declaration is valid in Cambridge pseudocode?
A CONSTANT Rate ← 6.50
B CONSTANT Total ← Rate * 2
2. Which constant declaration is NOT valid?
A CONSTANT Copy ← Rate
B CONSTANT MaxScore ← 100
3. True or false: CONSTANT Pi ← 3.14 is a valid constant declaration.
A True, 3.14 is a literal value
B False, a constant cannot hold a REAL value
4. Why is CONSTANT Total ← Rate * 2 invalid?
A The name Total is too long
B The value is an expression, not a literal
5. Which one gives a constant a literal value?
A CONSTANT Greeting ← UCASE(Word)
B CONSTANT Greeting ← "Hello"

Match the Pairs

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

Left columnRight column
1CONSTANT Rate ← 6.50 ACONSTANT MaxScore ← 100
2CONSTANT Total ← Rate * 2 BThe constant is set to another constant (Rate), not a literal. Use a literal such as CONSTANT Copy ← 6.50.
3A constant's value must be a literal, so a number written directly is allowed CThe value is an expression using a variable. Use a literal such as CONSTANT Tax ← 0.2.
4A constant's value must be a literal, so a text value written directly in quotes is allowed DNot valid: the value is an expression, not a literal
5CONSTANT Copy ← Rate EValid: the constant is set to the literal value 6.50
6CONSTANT Tax ← Price * 0.2 FCONSTANT School ← "Oakfield"

Definitions

CONSTANT Rate ← 6.50

Fill in the Blanks

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

1.
________ Rate ← 6.50
2.
CONSTANT Rate _ 6.50
3.
// The maximum score is 100 CONSTANT MaxScore ← ___
4.
CONSTANT Rate ← 5 // Literal for double the rate CONSTANT Double ← __
5.
DECLARE Count : INTEGER ________ Limit ← 10

Spot the Error

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

Question 1
A DECLARE Price : REAL
B CONSTANT VatRate ← Price * 0.2
C Price ← 10.00
D OUTPUT Price * VatRate
Question 2
A CONSTANT Rate ← 6.50
B CONSTANT Double ← Rate * 2
C OUTPUT Rate, Double
Question 3
A CONSTANT Rate ← 6.50
B DECLARE Hours : INTEGER
C Hours ← 4
D CONSTANT Copy ← Rate
Question 4
A DECLARE Name : STRING
B CONSTANT School ← Name
C Name ← "Sam"
D OUTPUT Name, School
Question 5
A CONSTANT Width ← 4
B CONSTANT Height ← 5
C CONSTANT Area ← Width * Height
D OUTPUT Area

Answer Key

A constant's value must be a literal
Section A: Quick Questions
Q1
A — CONSTANT Rate ← 6.50
Q2
A — CONSTANT Copy ← Rate
Q3
A — True, 3.14 is a literal value
Q4
B — The value is an expression, not a literal
Q5
B — CONSTANT Greeting ← "Hello"
Section B: Match the Pairs
Q1
CONSTANT Rate ← 6.50 → Valid: the constant is set to the literal value 6.50
Q2
CONSTANT Total ← Rate * 2 → Not valid: the value is an expression, not a literal
Q3
A constant's value must be a literal, so a number written directly is allowed → CONSTANT MaxScore ← 100
Q4
A constant's value must be a literal, so a text value written directly in quotes is allowed → CONSTANT School ← "Oakfield"
Q5
CONSTANT Copy ← Rate → The constant is set to another constant (Rate), not a literal. Use a literal such as CONSTANT Copy ← 6.50.
Q6
CONSTANT Tax ← Price * 0.2 → The value is an expression using a variable. Use a literal such as CONSTANT Tax ← 0.2.
Section C: Definitions
Q1
CONSTANT Rate ← 6.50 — A constant must be set to a literal value, such as 6.50. It cannot be given a variable, another constant or an expression like Rate * 2.
Section D: Fill in the Blanks
Q1
CONSTANT Rate ← 6.50
Q2
CONSTANT Rate ← 6.50
Q3
// The maximum score is 100 CONSTANT MaxScore ← 100
Q4
CONSTANT Rate ← 5 // Literal for double the rate CONSTANT Double ← 10
Q5
DECLARE Count : INTEGER CONSTANT Limit ← 10
Section E: Spot the Error
Q1
B — A constant's value must be a literal. Price * 0.2 uses a variable in an expression. It should be CONSTANT VatRate ← 0.2.
Q2
B — Rate * 2 is an expression, so it cannot be a constant's value. Use a literal: CONSTANT Double ← 13.00.
Q3
D — A constant cannot be set to another constant. Rate is a name, not a literal. It should be CONSTANT Copy ← 6.50.
Q4
B — A constant cannot be given a variable. Name is a variable, not a literal. It should be CONSTANT School ← "Oakwood".
Q5
C — Width * Height is an expression made from two constants. A constant needs a literal value: CONSTANT Area ← 20.