Snake casing

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

Snake casing

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which variable name uses snake casing?
A student_first_name
B studentFirstName
2. Which function definition follows Python's snake case convention?
A def calculate_total_price():
B def CalculateTotalPrice():
3. What is the snake case version of the camel case name highScore?
A high_Score
B high_score
4. Which name is correct snake casing for a variable?
A total_marks
B total marks
5. Which constant name follows the UPPER_SNAKE_CASE convention?
A max_attempts = 3
B MAX_ATTEMPTS = 3

Match the Pairs

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

Left columnRight column
1student_first_name = "Ava" AHyphens cannot be used in Python names. Words must be joined with underscores, so it should be get_average_mark.
2MAX_ATTEMPTS = 3 BA constant named in UPPER_SNAKE_CASE: all capitals with underscores between words
3Python functions are named in snake case, with lower case words joined by underscores CA Python variable named in snake case: all lower case with underscores between words
4Converting the camel case name studentFirstName to snake case DSnake case variable names must be all lower case. Capital letters should not be used, so it should be student_first_name.
5Student_First_Name = "Liam" Estudent_first_name
6def get-average-mark(marks): Fdef calculate_total_price(items):

Definitions

snake_case

Fill in the Blanks

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

1.
total_marks = 85
2.
__________ = "Ava" print(first_name)
3.
def _________(a, b): return a + b print(get_total(2, 3))
4.
_________ = 100 score = 120 print(score > MAX_SCORE)
5.
# camelCase: studentAge ___________ = 17

Spot the Error

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

Question 1
A first_name = 'Ava'
B lastName = 'Nguyen'
C print(first_name, last_name)
Question 2
A def get_total(price, qty):
B total_cost = price * qty
C return total_cost
D print(getTotal(2, 3))
Question 3
A score = 85
B bonus = 5
C total_score = score + bonus
D max_mark = 100
E print(total_score / MAX_MARK)
Question 4
A def get-average(marks):
B total = sum(marks)
C return total / len(marks)
Question 5
A age = 16
B min_age = 15
C Is_Eligible = age >= min_age
D print(is_eligible)

Answer Key

Snake casing
Section A: Quick Questions
Q1
A — student_first_name
Q2
A — def calculate_total_price():
Q3
B — high_score
Q4
A — total_marks
Q5
B — MAX_ATTEMPTS = 3
Section B: Match the Pairs
Q1
student_first_name = "Ava" → A Python variable named in snake case: all lower case with underscores between words
Q2
MAX_ATTEMPTS = 3 → A constant named in UPPER_SNAKE_CASE: all capitals with underscores between words
Q3
Python functions are named in snake case, with lower case words joined by underscores → def calculate_total_price(items):
Q4
Converting the camel case name studentFirstName to snake case → student_first_name
Q5
Student_First_Name = "Liam" → Snake case variable names must be all lower case. Capital letters should not be used, so it should be student_first_name.
Q6
def get-average-mark(marks): → Hyphens cannot be used in Python names. Words must be joined with underscores, so it should be get_average_mark.
Section C: Definitions
Q1
snake_case — A naming convention that writes every letter in lower case and joins words with underscores, e.g. student_first_name. Python uses it for variables and functions.
Section D: Fill in the Blanks
Q1
total_marks = 85
Q2
first_name = "Ava" print(first_name)
Q3
def get_total(a, b): return a + b print(get_total(2, 3))
Q4
MAX_SCORE = 100 score = 120 print(score > MAX_SCORE)
Q5
# camelCase: studentAge student_age = 17
Section E: Spot the Error
Q1
B — lastName is camelCase. Python variables use snake_case, so it should be last_name. The print line also expects last_name.
Q2
D — The function is defined as get_total, but this call uses camelCase. Function names in snake_case must be called with the same name: get_total(2, 3).
Q3
D — A constant should be written in UPPER_SNAKE_CASE, so it should be MAX_MARK. The lower case name also no longer matches the print line.
Q4
A — Snake case joins words with underscores, not hyphens. A hyphen is the minus operator in Python, so the name should be get_average.
Q5
C — Snake case uses only lower case letters. Is_Eligible has capitals, so it should be is_eligible, which is also the name used in print().