Camel casing

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

Camel casing

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which variable name is written in camel case?
A StudentFirstName
B studentFirstName
2. Which name is written in camel case?
A totalScore
B total_score
3. Which function name follows camel case?
A calculatetotal
B calculateTotal
4. Which name breaks the camel case pattern?
A Student_age
B studentAge
5. Which is the correct camel case version of the words 'average test mark'?
A averageTestMark
B AverageTestMark

Match the Pairs

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

Left columnRight column
1studentFirstName Adef getHighScore():
2calculateTotal() BThe name starts with a capital S. Camel case must start with a lower case letter, so it should be studentFirstName.
3Camel case variable name made from the words 'final mark' CA variable name in camel case: no spaces, starts lower case, and each later word starts with a capital
4Camel case function name made from the words 'get high score' DA function name in camel case: the first word is lower case and the next word is capitalised
5StudentFirstName = "Ava" EfinalMark = 85
6def calculate_total(): FThe name uses an underscore (snake case) instead of capitalising the second word. In camel case it should be calculateTotal.

Definitions

studentFirstName

Fill in the Blanks

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

1.
________________ = "Ava"
2.
def ______________(price, qty): return price * qty
3.
firstName = "Liam" lastName = "Smith" fullName = firstName + " " + ________
4.
for ___________ in names: print(studentName)
5.
def getAverageMark(m1, m2): return (m1 + m2) / 2 avgMark = ______________(80, 90)

Spot the Error

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

Question 1
A studentFirstName = 'Ava'
B StudentLastName = 'Nguyen'
C fullName = studentFirstName
D print(fullName)
Question 2
A def calculate_total(a, b):
B return a * b
C total = calculateTotal(3, 5)
D print(total)
Question 3
A itemPrice = 4.5
B itemCount = 3
C cost = itemPrice * itemCount
D totalcost = cost * 1.1
E print(totalCost)
Question 4
A def showGreeting(name):
B hello_text = 'Hi ' + name
C print(helloText)
D showGreeting('Ava')
Question 5
A playerScore = 0
B bonusPoints = 10
C PlayerScore += bonusPoints
D print(playerScore)

Answer Key

Camel casing
Section A: Quick Questions
Q1
B — studentFirstName
Q2
A — totalScore
Q3
B — calculateTotal
Q4
A — Student_age
Q5
A — averageTestMark
Section B: Match the Pairs
Q1
studentFirstName → A variable name in camel case: no spaces, starts lower case, and each later word starts with a capital
Q2
calculateTotal() → A function name in camel case: the first word is lower case and the next word is capitalised
Q3
Camel case variable name made from the words 'final mark' → finalMark = 85
Q4
Camel case function name made from the words 'get high score' → def getHighScore():
Q5
StudentFirstName = "Ava" → The name starts with a capital S. Camel case must start with a lower case letter, so it should be studentFirstName.
Q6
def calculate_total(): → The name uses an underscore (snake case) instead of capitalising the second word. In camel case it should be calculateTotal.
Section C: Definitions
Q1
studentFirstName — Camel casing: join words with no spaces, start with a lower case letter, then capitalise the first letter of each later word, e.g. studentFirstName or calculateTotal.
Section D: Fill in the Blanks
Q1
studentFirstName = "Ava"
Q2
def calculateTotal(price, qty): return price * qty
Q3
firstName = "Liam" lastName = "Smith" fullName = firstName + " " + lastName
Q4
for studentName in names: print(studentName)
Q5
def getAverageMark(m1, m2): return (m1 + m2) / 2 avgMark = getAverageMark(80, 90)
Section E: Spot the Error
Q1
B — Camel case must start with a lower case letter. StudentLastName starts with a capital, which is Pascal case. It should be studentLastName.
Q2
A — Function names in camel case have no underscores. Each new word starts with a capital letter. It should be calculateTotal.
Q3
D — The second word must start with a capital letter in camel case. totalcost runs the words together in lower case. It should be totalCost.
Q4
B — hello_text is snake case because it uses an underscore. Camel case joins the words and capitalises the second one. It should be helloText.
Q5
C — A camel case name starts with a lower case letter. PlayerScore starts with a capital, so it breaks the pattern. It should be playerScore.