← VCE Software Development U3O1

Constants

A constant: a named value set once and never changed while the program runs. Written in UPPER_CASE by convention, it replaces magic numbers and is easy to update in one place.

Understanding Constants in VCE Software Development U3O1

What it does: The 0.1 is a magic number because nobody can tell what it means. Replacing it with GST_RATE would fix this. The score variable is reassigned as the program runs. A constant such as GST_RATE is never reassigned after it is defined. By convention, constants are written in UPPER_CASE with underscores between words, so GST_RATE stands out as a value that should not change. Defining constants at the top makes them easy to find and change in one place. With a constant, one edit at the top of the program updates every line that uses it. Magic numbers must be hunted down one by one.

Common mistakes: This adds the rate (0.1) to the price instead of the GST amount. It should be total = price + gst. The constant was defined as MAX_ITEMS in upper case. Python is case-sensitive, so max_items causes a NameError. It should be MAX_ITEMS.

Class: _____________________  ·  Name: _____________________  ·  Date: _________

Free printable worksheet with full answer key — or add this module to a class and your students practise it interactively.

This module's key terms are also in a printable crossword (Modules 10–47) and word search (Modules 10–71).

Take this worksheet further — free with Cloodit

Each concept is reinforced from every angle — learned, then applied, then tested.

Learning
Duo
Which line follows the Python convention for naming a constant?
GST_RATE = 0.1gstRate = 0.1
Matches
gst_rate = 0.1
↓
The constant is written in lower case. By convention constants use UPPER_CASE, such as GST_RATE, so readers know it must not change.
Applying
Meanings
Term
GST_RATE = 0.1
Meaning
A constant: a named value set once and never changed while the program runs. Written in UPPER_CASE by convention, it replaces magic numbers and is easy to update in one place.
Practice
GST_RATE = 0.1
Testing
Gaps
= 0.1
Check Answer
Spots
3gst = price * GST_RATE
4total = price + GST_RATE

Cloodit turns curriculum-aligned coding content into journeys students work through one biome at a time.

The 'Thorny Devil' badge — Detail Master, one of Cloodit's 106 collectible badges
Students earn collectable badges

Over 100 of them, across seven natural biomes.

Study Buddy
Students build a real study resource

Turns their work into revision material ready for Flash Cards and Exam study.

Diamond Dash — one of Cloodit's live, competitive Sprint games
Students lock in with Sprints

Live, competitive practice for the start of the lesson or a teacher-led lesson finisher.

A Cloodit certificate of achievement, ready to personalise and print
Custom printable certificates

Honour your top performers, or encourage a student who's trying hard — ready to print in seconds.

Quick Questions

1. Which line follows the Python convention for naming a constant?
A. GST_RATE = 0.1 ✓
B. gstRate = 0.1
By convention, constants are written in UPPER_CASE with underscores between words, so GST_RATE stands out as a value that should not change.
2. Where should constants normally be defined in a program?
A. At the top of the program, before they are used ✓
B. Buried in the middle of a loop
Defining constants at the top makes them easy to find and change in one place.
3. Which statement about a constant is correct?
A. Its value is set once and not changed while the program runs ✓
B. Its value changes every time the user enters data
A variable can change as the program runs. A constant is set once and then left alone.
4. Which one is best stored as a constant?
A. score = 0
B. MAX_ATTEMPTS = 3 ✓
The maximum number of attempts is fixed for the whole program. A score changes as the program runs, so it is a variable.
5. Which line avoids a 'magic number'?
A. total = price * 0.1
B. total = price * GST_RATE ✓
A magic number is an unexplained value written directly in code. A named constant such as GST_RATE tells the reader what 0.1 means.

Match the Pairs

GST_RATE = 0.1 → Defines a constant named GST_RATE with the value 0.1, set once and not changed while the program runs
total = price * GST_RATE → Uses the constant's name instead of a magic number, so the 0.1 is not hard-coded in the calculation
A magic number is an unexplained value typed directly into code, which a named constant avoids → tax = price * 0.1
A variable can change as the program runs, but a constant should stay the same → score = score + 1
gst_rate = 0.1 → The constant is written in lower case. By convention constants use UPPER_CASE, such as GST_RATE, so readers know it must not change.
GST_RATE = 0.1 GST_RATE = 0.15 → The constant is reassigned partway through the program. A constant must be set once and never changed while the program runs.

Key Term

GST_RATE = 0.1
A constant: a named value set once and never changed while the program runs. Written in UPPER_CASE by convention, it replaces magic numbers and is easy to update in one place.

Fill in the Blanks

1. GST_RATE = 0.1
Hint: Type the constant's name, written in UPPER_CASE with an underscore between the words
2. GST = 0.1
Hint: Type the operator that assigns a value to the constant's name
3. total = price * (1 + GST_RATE)
Hint: Type the constant name that replaces the magic number for the tax rate
4. if score >= PASS_MARK:
Hint: Type the UPPER_CASE constant that holds the pass mark instead of a magic number
5. seconds = minutes * SECONDS_PER_MINUTE
Hint: Type the arithmetic operator that converts minutes to seconds using the constant

Spot the Error

Question 1
A GST_RATE = 0.1
B price = 50
C gst = price * GST_RATE
D total = price + GST_RATE
E print(total)
Line D — This adds the rate (0.1) to the price instead of the GST amount. It should be total = price + gst.
Question 2
A MAX_ITEMS = 5
B items = 0
C items = items + 1
D if items > max_items:
E print("Full")
Line D — The constant was defined as MAX_ITEMS in upper case. Python is case-sensitive, so max_items causes a NameError. It should be MAX_ITEMS.
Question 3
A PI = 3.14159
B radius = 4
C area = 3.14159 * radius ** 2
D print(area)
Line C — This types the number directly (a magic number) instead of using the constant PI. It should be area = PI * radius ** 2.
Question 4
A TAX_RATE = 0.1
B price = "200"
C tax = price * TAX_RATE
D print(tax)
Line B — The quotes make price a string, so multiplying it by the float TAX_RATE causes a TypeError. It should be price = 200.
Question 5
A MAX SPEED = 100
B speed = 80
C if speed > MAX_SPEED:
D print("Too fast")
Line A — Names cannot contain spaces, so this is a syntax error. Use an underscore: MAX_SPEED = 100.

Student with a class code? Join your class →