What a constant is

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

What a constant is

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. A constant is a named value that can be changed many times while the program runs.
A False
B True
2. Which line declares a constant in Cambridge pseudocode?
A CONSTANT Pi ← 3.142
B DECLARE Pi : CONSTANT
3. Which value is best stored as a constant?
A Score, a number that goes up for each correct answer
B HourlyRate, a fixed pay rate of 12.50
4. What is the main difference between a constant and a variable?
A A constant can change; a variable keeps the same value
B A constant keeps the same value; a variable's value can change
5. When is the value of a constant set?
A Once, before the program runs
B Again and again while the program runs

Match the Pairs

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

Left columnRight column
1CONSTANT Pi ← 3.142 AThe second line tries to change the value of a constant, but a constant is set once and cannot change while the program runs.
2CONSTANT HourlyRate ← 12.50 BCreates a named value Pi that is fixed at 3.142 and cannot change while the program runs
3A constant is set once before the program runs, so its value is written when it is named CCONSTANT MaxScore ← 100
4A variable can be given new values as the program runs, unlike a constant DCreates a named pay rate of 12.50 that stays the same every time the program uses it
5CONSTANT Pi ← 3.142 Pi ← 3.14159 EHourlyRate is meant to be fixed, but this declares it as a variable, so it could be changed later in the program.
6DECLARE HourlyRate : REAL HourlyRate ← 12.50 FScore ← Score + 10

Definitions

CONSTANT

Fill in the Blanks

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

1.
________ Pi ← 3.142
2.
CONSTANT __________ ← 12.50
3.
CONSTANT Pi _ 3.142
4.
CONSTANT HourlyRate ← 12.50 Pay ← Hours * __________
5.
CONSTANT Pi ← 3.142 Area ← __ * Radius ^ 2

Spot the Error

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

Question 1
A CONSTANT HourlyRate ← 12.50
B DECLARE Hours : INTEGER
C HourlyRate ← 15.00
D OUTPUT HourlyRate * Hours
Question 2
A CONSTANT Pi = 3.142
B DECLARE Radius : REAL
C Radius ← 5
D OUTPUT Pi * Radius ^ 2
Question 3
A CONSTANT MaxScore ← 100
B DECLARE Score : INTEGER
C MaxScore ← 85
D OUTPUT Score, " out of ", MaxScore
Question 4
A DECLARE Total : REAL
B CONSTANT VatRate
C Total ← 50 * VatRate
D OUTPUT Total
Question 5
A CONSTANT Pi ← 3.142
B DECLARE Radius : REAL
C DECLARE Area : REAL
D INPUT Pi
E Area ← Pi * Radius ^ 2

Answer Key

What a constant is
Section A: Quick Questions
Q1
A — False
Q2
A — CONSTANT Pi ← 3.142
Q3
B — HourlyRate, a fixed pay rate of 12.50
Q4
B — A constant keeps the same value; a variable's value can change
Q5
A — Once, before the program runs
Section B: Match the Pairs
Q1
CONSTANT Pi ← 3.142 → Creates a named value Pi that is fixed at 3.142 and cannot change while the program runs
Q2
CONSTANT HourlyRate ← 12.50 → Creates a named pay rate of 12.50 that stays the same every time the program uses it
Q3
A constant is set once before the program runs, so its value is written when it is named → CONSTANT MaxScore ← 100
Q4
A variable can be given new values as the program runs, unlike a constant → Score ← Score + 10
Q5
CONSTANT Pi ← 3.142 Pi ← 3.14159 → The second line tries to change the value of a constant, but a constant is set once and cannot change while the program runs.
Q6
DECLARE HourlyRate : REAL HourlyRate ← 12.50 → HourlyRate is meant to be fixed, but this declares it as a variable, so it could be changed later in the program.
Section C: Definitions
Q1
CONSTANT — A named value set once before the program runs that never changes, unlike a variable. Example: CONSTANT Pi ← 3.142 or CONSTANT HourlyRate ← 12.50 are fixed while the program runs.
Section D: Fill in the Blanks
Q1
CONSTANT Pi ← 3.142
Q2
CONSTANT HourlyRate ← 12.50
Q3
CONSTANT Pi ← 3.142
Q4
CONSTANT HourlyRate ← 12.50 Pay ← Hours * HourlyRate
Q5
CONSTANT Pi ← 3.142 Area ← Pi * Radius ^ 2
Section E: Spot the Error
Q1
C — HourlyRate is a constant, so its value cannot be changed while the program runs. This line should assign to the variable instead: Hours ← 8.
Q2
A — A constant is given its value with the assignment arrow ←, not =. It should be CONSTANT Pi ← 3.142.
Q3
C — MaxScore is a constant set once at the start, so it cannot be assigned a new value. The variable Score should be assigned: Score ← 85.
Q4
B — A constant must be given its fixed value when it is set up. The line should be CONSTANT VatRate ← 0.2.
Q5
D — INPUT would change Pi while the program runs, but a constant never changes. The user should enter the variable instead: INPUT Radius.