← VCE Software Development U3O1

Comments that explain and justify data and code structures

A comment that explains what a variable, array, record or algorithm is for and why it was chosen, rather than just repeating what the code does.

Understanding Comments that explain and justify data and code structures in VCE Software Development U3O1

What it does: The comment gives the loop's purpose (finding the highest mark) instead of just saying 'a for loop'. The comment gives the reason for the structure: a record groups fields of different data types for one student. A good comment explains WHY the structure was chosen (fixed size), not just what it is. Describing a variable's purpose says what it is used for in the program, not just its starting value. The wrong option just reads the code aloud. The correct one explains the rule behind the decision. Justifying the choice (fast lookup by key) helps maintainers understand the design decision.

Common mistakes: Python comments start with #, not //. The // line is invalid code and causes a syntax error. It should be '# total: sum used for average'. The comment gives the wrong reason for the array's size. The code creates 7 elements, so the comment must say 7 days. A comment that contradicts the code misleads the next programmer.

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 48–71) 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 comment best justifies a choice of data structure?
# array used because the size is fixed at 30 students# this is an array
Matches
# set count to 0 count = 0
↓
The comment only repeats what the code does and does not explain what count is for. Better: # count tracks how many students passed
Applying
Meanings
Term
# array used because size is fixed
Meaning
A comment that explains what a variable, array, record or algorithm is for and why it was chosen, rather than just repeating what the code does.
Practice
marks = [0] * 30
Testing
Gaps
Check Answer
Spots
3total = 0
4// total: sum used for average

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

The 'Arctic Hare' badge — Speed Indexer, 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 comment best justifies a choice of data structure?
A. # this is an array
B. # array used because the size is fixed at 30 students ✓
A good comment explains WHY the structure was chosen (fixed size), not just what it is.
2. Which comment best describes the purpose of the variable totalMarks?
A. # totalMarks holds the running sum of all test marks for the class average ✓
B. # totalMarks equals 0
Describing a variable's purpose says what it is used for in the program, not just its starting value.
3. Which comment avoids simply repeating the code? count = count + 1
A. # count tracks how many students passed ✓
B. # add 1 to count
'Add 1 to count' just restates the code. A useful comment explains what the count means.
4. Which comment best explains why a loop is used?
A. # loop through every mark so each one is added to the total ✓
B. # for loop
A good loop comment explains what the loop achieves and why it is needed.
5. Which comment best justifies using a record for a student?
A. # student record
B. # record used because name, age and mark are different data types ✓
Records group related fields of different data types, and the comment should give that reason.

Match the Pairs

# total holds the running sum of all marks → A comment describing a variable's purpose: what the variable is for
# list used because the number of students can change → A comment justifying the choice of data structure by giving the reason it was chosen
A comment that explains why a loop is used and what it achieves → # loop through every mark to find the highest for mark in marks:
A comment that justifies using a record to group related data of different types → # record used to keep one student's name, age and mark together student = {"name": "Ava", "age": 16, "mark": 88}
# set count to 0 count = 0 → The comment only repeats what the code does and does not explain what count is for. Better: # count tracks how many students passed
# this is an array scores = [0] * 30 → The comment names the structure but gives no reason for choosing it. Better: # array used because the size is fixed at 30 students

Key Term

# array used because size is fixed
A comment that explains what a variable, array, record or algorithm is for and why it was chosen, rather than just repeating what the code does.

Fill in the Blanks

1. # total of all marks, used to find the average total = 0
Hint: Type the symbol that starts a Python comment.
2. # loop runs once for each of the 30 students for i in range(30): marks.append(0)
Hint: Type the keyword that starts a loop over a known number of items.
3. # dictionary used so marks are found by name marks = {}
Hint: Type the empty brackets that create a dictionary.
4. # repeat until a valid mark is entered while mark < 0 or mark > 100: mark = int(input("Mark: "))
Hint: Type the keyword for a loop that repeats while its condition is true.
5. # list used because the size is fixed at 30 names = [""] * 30
Hint: Type the operator that repeats a list item a set number of times.

Spot the Error

Question 1
A # fixed size: 30 students
B marks = [0] * 30
C total = 0
D // total: sum used for average
E for m in marks: total += m
Line D — Python comments start with #, not //. The // line is invalid code and causes a syntax error. It should be '# total: sum used for average'.
Question 2
A # array: 5 days, size fixed
B temps = [0] * 7
C for d in range(7):
D temps[d] = d + 20
Line A — The comment gives the wrong reason for the array's size. The code creates 7 elements, so the comment must say 7 days. A comment that contradicts the code misleads the next programmer.
Question 3
A students = []
B students.append("Mia")
C # array used: size is fixed
D print(len(students))
Line C — The comment justifies the structure with the wrong reason. The code uses append(), so the size grows. It should say the list was chosen because its size can change.
Question 4
A tests = 5
B for i in range(tests):
C # for i in range(tests)
D print(i + 1)
Line C — This comment only repeats the code. A good comment explains why the loop exists, such as '# loop: one pass per test'.
Question 5
A mark = 72
B # pass mark is 50 or more
C if mark >= 60:
D print("Pass")
Line C — The comment says the pass mark is 50, but the condition tests for 60. The code and its explanation must agree, so the condition should be mark >= 50.

Student with a class code? Join your class →