Header comments for code maintenance

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

Header comments for code maintenance

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Where should a header comment go in a program file?
A Hidden at the bottom of the file
B At the very top of the file
2. Which header comment is more useful for maintenance?
A # Purpose: Calculate student grade averages
B # This is my program
3. What does the author and date part of a header comment tell a maintainer?
A How fast the program will run on the computer
B Who wrote the code and when, so they know who to ask and how old it is
4. A programmer fixes a bug in a file. What should they do with the header comment?
A Add a line to the change log with the date and what was changed
B Delete the old header so the file looks tidy
5. Which line is a valid Python header comment line for a version note?
A # Version: 1.2 - added input validation
B Version: 1.2 - added input validation

Match the Pairs

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

Left columnRight column
1# Author: Mia Chen ARecords who wrote the program so others know who to ask about it
2# Version 1.2 - added input validation B# Purpose: Calculates the total cost of a school canteen order
3A change log in a header comment records each edit, with its date, so maintainers can see how the file has changed CThe header comment is placed below the code instead of at the top of the file, so it is not easy to find.
4A header comment states the program's purpose at the top of the file so others know what it does D# Changed 12/03/2025: fixed tax calculation
5total = 0 # Author: Sam Lee # Date: 04/05/2025 EA version note that says which release this is and what changed
6# Program: Quiz game # Author: Ravi Patel total = 0 FThe header has no date and no change log, so maintainers cannot tell when it was written or what was modified.

Definitions

header comment

Fill in the Blanks

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

1.
_ Purpose: Calculate GST on prices
2.
# ______: Sam Lee
3.
# ____: 14/03/2025
4.
# _______: 1.2
5.
# __________: Added input validation

Spot the Error

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

Question 1
A # Purpose: Quiz score tracker
B # Author: Mia Chen
C Date: 12/03/2025
D score = 0
Question 2
A # Purpose: Temp converter
B # Author: Sam Lee
C // Version: 1.2 (added Kelvin)
D temp = 25
Question 3
A # Purpose: Grade calculator
B # Author:
C # Date: 03/06/2025
D total = 0
Question 4
A # Purpose: stuff
B # Author: Kai Tran
C # Date: 20/07/2025
D books = []
Question 5
A /* Purpose: Work out GST */
B # Author: Ali Khan
C # Date: 14/08/2025
D price = 49.95

Answer Key

Header comments for code maintenance
Section A: Quick Questions
Q1
B — At the very top of the file
Q2
A — # Purpose: Calculate student grade averages
Q3
B — Who wrote the code and when, so they know who to ask and how old it is
Q4
A — Add a line to the change log with the date and what was changed
Q5
A — # Version: 1.2 - added input validation
Section B: Match the Pairs
Q1
# Author: Mia Chen → Records who wrote the program so others know who to ask about it
Q2
# Version 1.2 - added input validation → A version note that says which release this is and what changed
Q3
A change log in a header comment records each edit, with its date, so maintainers can see how the file has changed → # Changed 12/03/2025: fixed tax calculation
Q4
A header comment states the program's purpose at the top of the file so others know what it does → # Purpose: Calculates the total cost of a school canteen order
Q5
total = 0 # Author: Sam Lee # Date: 04/05/2025 → The header comment is placed below the code instead of at the top of the file, so it is not easy to find.
Q6
# Program: Quiz game # Author: Ravi Patel total = 0 → The header has no date and no change log, so maintainers cannot tell when it was written or what was modified.
Section C: Definitions
Q1
header comment — A comment at the top of a file that records the program's purpose, author, date and any changes made, so others can understand and maintain the code.
Section D: Fill in the Blanks
Q1
# Purpose: Calculate GST on prices
Q2
# Author: Sam Lee
Q3
# Date: 14/03/2025
Q4
# Version: 1.2
Q5
# Change log: Added input validation
Section E: Spot the Error
Q1
C — The date line is missing the # symbol, so Python reads it as code and gives a syntax error. It should be '# Date: 12/03/2025'.
Q2
C — // is not a comment in Python, so the version note causes a syntax error. A Python header comment line must start with #.
Q3
B — The author line has no name. A header comment must say who wrote the program so others know who to ask. It should be '# Author: Jo Park'.
Q4
A — The purpose is too vague to help anyone maintain the code. It should say what the program does, such as '# Purpose: Library checker'.
Q5
A — /* */ comments are not valid in Python, so this line causes a syntax error. The header line should start with #: '# Purpose: Work out GST'.