Identifiers are case insensitive

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

Identifiers are case insensitive

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. In Cambridge pseudocode, are Score and SCORE the same identifier?
A No, they are two different variables because the capital letters differ
B Yes, they are the same name because identifiers are case insensitive
2. A student writes DECLARE Countdown : INTEGER and then DECLARE CountDown : INTEGER. What is wrong?
A Nothing is wrong, because each name has a different capital D
B The two names are the same identifier, so the variable is declared twice
3. Which choice follows good practice for two different values, a player's total and a player's best score?
A TotalScore and BestScore
B Score and SCORE
4. Why is mixed case such as FirstName useful in an identifier?
A The capital letter shows where a new word starts, so the name is easier to read
B The capital letter makes it a different variable from firstname
5. A program uses Total ← 5 and later OUTPUT TOTAL. What is output?
A 5, because TOTAL is the same variable as Total
B Nothing, because TOTAL is a different variable with no value

Match the Pairs

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

Left columnRight column
1Score ← 10 score ← 20 ADECLARE HighScore : INTEGER DECLARE LowScore : INTEGER
2DECLARE PlayerName : STRING BMixed case marks where each new word starts, making the name easier to read
3Identifiers are case insensitive, so these two names refer to the same variable CTotalMarks and totalmarks
4Avoid near-duplicate names by giving each variable a clearly different name DTotal, TOTAL and total look different but are one variable, which is confusing to read.
5DECLARE Countdown : INTEGER DECLARE CountDown : INTEGER EThe two names differ only in capital letters, so they are the same identifier and are declared twice.
6Total ← 5 TOTAL ← Total + 1 OUTPUT total FBoth lines change the same variable, so Score now holds 20

Definitions

case insensitive

Fill in the Blanks

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

1.
DECLARE Countdown : _______ COUNTDOWN ← 10 OUTPUT countdown
2.
_______ PlayerName : STRING PLAYERNAME ← "Sam" OUTPUT playername
3.
DECLARE Lives : INTEGER Lives _ 3 OUTPUT LIVES
4.
DECLARE HighScore : INTEGER HighScore ← 50 OUTPUT _________
5.
DECLARE Age : INTEGER _____ AGE OUTPUT age

Spot the Error

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

Question 1
A DECLARE Total : INTEGER
B Total ← 0
C DECLARE TOTAL : INTEGER
D OUTPUT Total
Question 2
A DECLARE bonus : INTEGER
B DECLARE Bonus : INTEGER
C Lives ← 3
Question 3
A DECLARE Price : REAL
B CONSTANT TaxRate ← 0.2
C DECLARE TAXRATE : REAL
D Total ← Price * (1 + TaxRate)
Question 4
A DECLARE Speed : REAL
B DECLARE Time : REAL
C Speed ← 12.5
D DECLARE speed : REAL
E Distance ← Speed * Time
Question 5
A DECLARE Total : INTEGER
B Total ← 0
C Total ← Total + 5
D // TOTAL is a different variable

Answer Key

Identifiers are case insensitive
Section A: Quick Questions
Q1
B — Yes, they are the same name because identifiers are case insensitive
Q2
B — The two names are the same identifier, so the variable is declared twice
Q3
A — TotalScore and BestScore
Q4
A — The capital letter shows where a new word starts, so the name is easier to read
Q5
A — 5, because TOTAL is the same variable as Total
Section B: Match the Pairs
Q1
Score ← 10 score ← 20 → Both lines change the same variable, so Score now holds 20
Q2
DECLARE PlayerName : STRING → Mixed case marks where each new word starts, making the name easier to read
Q3
Identifiers are case insensitive, so these two names refer to the same variable → TotalMarks and totalmarks
Q4
Avoid near-duplicate names by giving each variable a clearly different name → DECLARE HighScore : INTEGER DECLARE LowScore : INTEGER
Q5
DECLARE Countdown : INTEGER DECLARE CountDown : INTEGER → The two names differ only in capital letters, so they are the same identifier and are declared twice.
Q6
Total ← 5 TOTAL ← Total + 1 OUTPUT total → Total, TOTAL and total look different but are one variable, which is confusing to read.
Section C: Definitions
Q1
case insensitive — Capital letters do not matter in identifiers, so Countdown and CountDown are the same name. Never use names that differ only in case as two separate variables.
Section D: Fill in the Blanks
Q1
DECLARE Countdown : INTEGER COUNTDOWN ← 10 OUTPUT countdown
Q2
DECLARE PlayerName : STRING PLAYERNAME ← "Sam" OUTPUT playername
Q3
DECLARE Lives : INTEGER Lives ← 3 OUTPUT LIVES
Q4
DECLARE HighScore : INTEGER HighScore ← 50 OUTPUT HIGHSCORE
Q5
DECLARE Age : INTEGER INPUT AGE OUTPUT age
Section E: Spot the Error
Q1
C — TOTAL and Total are the same identifier because capital letters do not matter. This declares the same variable twice. Use a different name, such as Count.
Q2
A — bonus on line 1 and Bonus on line 2 differ only in case, so they are the same name. Two variables cannot share one identifier. Line 1 should declare a different name, such as Lives.
Q3
C — TAXRATE is the same identifier as the constant TaxRate, because case is ignored. A name cannot be both a constant and a variable. Line 3 should declare a different name, such as Total.
Q4
D — speed is the same identifier as Speed, which is already declared on line 1. Changing the capitals does not make a new variable. Line 4 should declare a new name, Distance.
Q5
D — The comment is wrong. Identifiers are case insensitive, so TOTAL and Total are the same variable, not different ones.