Hungarian notation

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

Hungarian notation

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which variable name uses Hungarian notation to store a student's name as text?
A strName
B nameStr5
2. Which prefix would you use for a variable that holds a whole number such as an age?
A blnAge
B intAge
3. Which name best suits a variable holding the price of an item, such as 4.50?
A fltPrice
B strPrice
4. Which name best suits a variable that stores True or False for whether a student passed?
A intPassed
B blnPassed
5. Where does the data type prefix go in Hungarian notation?
A At the start of the name, like intScore
B At the end of the name, like scoreInt

Match the Pairs

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

Left columnRight column
1strFirstName AfltPrice
2blnPassed BThe int prefix is wrong because the value is text. It should use str, as in strStudentName.
3An integer variable for a student's age using Hungarian notation and camel casing CA string variable, shown by the str prefix before the descriptive name FirstName
4A float variable holding a decimal price, with the data type prefix first DThe name has no data type prefix. Hungarian notation needs one, such as intAge.
5intStudentName = "Ava" EA Boolean variable holding True or False, shown by the bln prefix
6age = 16 FintStudentAge

Definitions

Hungarian notation

Fill in the Blanks

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

1.
___Name = "Ava"
2.
___Age = 16
3.
___Price = 4.5
4.
___IsMember = False
5.
blnPassed = True if _________: print("Well done")

Spot the Error

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

Question 1
A strName = "Mia"
B intAge = 16
C intPrice = 4.50
D print(strName, fltPrice)
Question 2
A intScore = 18
B intTotal = 20
C strPassed = intScore >= 10
D print(blnPassed)
Question 3
A strFirst = "Ali"
B strlast = "Khan"
C strFull = strFirst + strLast
Question 4
A fltPrice = 12.50
B qtyInt = 3
C fltTotal = fltPrice * intQty
D print(fltTotal)
Question 5
A strName = "Zoe"
B intMark = 62
C fltAvg = 62.5
D boolPassed = intMark >= 50

Answer Key

Hungarian notation
Section A: Quick Questions
Q1
A — strName
Q2
B — intAge
Q3
A — fltPrice
Q4
B — blnPassed
Q5
A — At the start of the name, like intScore
Section B: Match the Pairs
Q1
strFirstName → A string variable, shown by the str prefix before the descriptive name FirstName
Q2
blnPassed → A Boolean variable holding True or False, shown by the bln prefix
Q3
An integer variable for a student's age using Hungarian notation and camel casing → intStudentAge
Q4
A float variable holding a decimal price, with the data type prefix first → fltPrice
Q5
intStudentName = "Ava" → The int prefix is wrong because the value is text. It should use str, as in strStudentName.
Q6
age = 16 → The name has no data type prefix. Hungarian notation needs one, such as intAge.
Section C: Definitions
Q1
Hungarian notation — Starting a variable name with a short data type prefix, then a descriptive name, such as strName, intAge, fltPrice or blnPassed.
Section D: Fill in the Blanks
Q1
strName = "Ava"
Q2
intAge = 16
Q3
fltPrice = 4.5
Q4
blnIsMember = False
Q5
blnPassed = True if blnPassed: print("Well done")
Section E: Spot the Error
Q1
C — The value 4.50 is a decimal number, so the prefix must be flt, not int. The line should be fltPrice = 4.50.
Q2
C — The comparison gives True or False, which is a Boolean. The prefix should be bln, so the name should be blnPassed, not strPassed.
Q3
B — After the prefix, the descriptive name must start with a capital letter (camel casing). It should be strLast. The other lines also refer to strLast.
Q4
B — In Hungarian notation the data type prefix goes at the START of the name, not the end. It should be intQty.
Q5
D — The agreed prefix for a Boolean variable is bln, not bool. The line should be blnPassed = intMark >= 50.