Naming conventions for solution elements

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

Naming conventions for solution elements

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which variable name follows good naming practice for storing a student's test score?
A test_score
B x
2. Which is the better name for a constant holding the GST rate in Python?
A gstrate
B GST_RATE
3. A program follows snake_case for variables. Which new variable name is consistent with that convention?
A total_price
B TotalPrice
4. Which class name follows the common Python convention?
A StudentRecord
B student_record
5. True or false: A naming convention only matters to the computer, not to the people reading the code.
A True
B False

Match the Pairs

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

Left columnRight column
1MAX_STUDENTS = 30 AA constant named in UPPER_SNAKE_CASE so it stands out as a value that should not change
2class StudentRecord: Bfirst_name = "Ava" last_name = "Nguyen" year_level = 7
3A meaningful name describes what the data stores, so the code is easy to read CThe variable names mix snake_case, PascalCase and camelCase, so the program is inconsistent
4Consistency means using the same naming pattern for every variable throughout a program Dtotal_price = quantity * unit_price
5x = 15 y = 4 z = x * y EA class name written in PascalCase, with each word starting with a capital letter
6first_name = "Liam" LastName = "Smith" yearLevel = 8 FThe names x, y and z are not meaningful, so a reader cannot tell what the values represent

Definitions

naming convention

Fill in the Blanks

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

1.
___________ = 78 + 85 average_mark = total_marks / 2
2.
class _____________: pass rec = StudentRecord()
3.
________ = 0.1 price = 50 total = price + price * GST_RATE
4.
def _______________(price, qty): return price * qty cost = calculate_total(4, 3)
5.
________ = 0 max_mark = 100 print(min_mark, max_mark)

Spot the Error

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

Question 1
A MAX_ATTEMPTS = 3
B attempts = 0
C while attempts < max_attempts:
D attempts += 1
Question 2
A # Class for a library book
B class book_item:
C def __init__(self, title):
D self.title = title
Question 3
A let studentName = 'Ava';
B let studentAge = 15;
C let student_score = 88;
D console.log(studentName);
Question 4
A price = 12.50
B x = 3
C total_cost = price * quantity
D print(total_cost)
Question 5
A score = 78
B MAX_SCORE = 100
C PASS_MARK = 50
D top_mark = 90
E passed = score >= PASS_MARK

Answer Key

Naming conventions for solution elements
Section A: Quick Questions
Q1
A — test_score
Q2
B — GST_RATE
Q3
A — total_price
Q4
A — StudentRecord
Q5
B — False
Section B: Match the Pairs
Q1
MAX_STUDENTS = 30 → A constant named in UPPER_SNAKE_CASE so it stands out as a value that should not change
Q2
class StudentRecord: → A class name written in PascalCase, with each word starting with a capital letter
Q3
A meaningful name describes what the data stores, so the code is easy to read → total_price = quantity * unit_price
Q4
Consistency means using the same naming pattern for every variable throughout a program → first_name = "Ava" last_name = "Nguyen" year_level = 7
Q5
x = 15 y = 4 z = x * y → The names x, y and z are not meaningful, so a reader cannot tell what the values represent
Q6
first_name = "Liam" LastName = "Smith" yearLevel = 8 → The variable names mix snake_case, PascalCase and camelCase, so the program is inconsistent
Section C: Definitions
Q1
naming convention — An agreed pattern for naming variables, functions, classes and constants so code is consistent, uses meaningful names and is easy to read.
Section D: Fill in the Blanks
Q1
total_marks = 78 + 85 average_mark = total_marks / 2
Q2
class StudentRecord: pass rec = StudentRecord()
Q3
GST_RATE = 0.1 price = 50 total = price + price * GST_RATE
Q4
def calculate_total(price, qty): return price * qty cost = calculate_total(4, 3)
Q5
min_mark = 0 max_mark = 100 print(min_mark, max_mark)
Section E: Spot the Error
Q1
C — The constant was named MAX_ATTEMPTS in upper case. Using max_attempts breaks the convention and the program's consistency, and it would also cause an error because that name does not exist. It should be MAX_ATTEMPTS.
Q2
B — Class names should use PascalCase (each word starts with a capital, no underscores) so they stand out from variables. The line should be class Book: to match the rest of the program.
Q3
C — The rest of the program uses camelCase for variables. Switching to snake_case on one line is inconsistent. It should be let studentScore = 88;.
Q4
B — The name x does not say what the value means. Meaningful names make code easier to read and maintain. It should be quantity = 3.
Q5
D — Constants are written in UPPER_CASE with underscores, like MAX_SCORE and PASS_MARK. The lower-case name top_mark looks like an ordinary variable and breaks consistency. It should be TOP_MARK = 90.