D278 Practice Exam 2 Questions with Verified
Correct Answers
A vending machine starts with 7 sodas. After restocking, the code runs: x = 7; x = x + 3. What is
the final value of x?
10
A warehouse tracks pallets. The code runs: y = 4; z = y * 2; y = y + z. What is the final value of
y?
12
A programmer names a variable "3rdPlace" to store a contestant's ranking. Is "3rdPlace" a
valid identifier?
No (starts with a digit)
A programmer names a variable "_userName" to store the username. Is "_userName" a valid
identifier?
No (must start with a letter)
A program tracks the number of windows in a house. Which is the best identifier?
numWindowsHouse
A student writes "2y" to mean "two times y" in an expression. Is "2y" a valid expression?
No (missing multiplication operator)
A program evaluates the expression a - b * c. Which operator is evaluated first?
*
A program evaluates m + 2 * n / 4. Which parenthesization matches the actual evaluation
order?
m + ((2 * n) / 4)
An inventory program runs: numItems = 4; totCount = 3 + (2 numItems) 5. What is the value
of totCount?
, 43
A programmer tries to name a loop counter "while". Is "while" a valid identifier?
No (reserved word)
A program needs to compute "5 more than triple x". Which expression correctly captures
this?
(3 * x) + 5
A shipping company charges: "Too heavy" if weight > 200, "Warning" if weight > 180, else
"OK". Which if statement type is needed?
If-elseif
An age permissions program runs: if userAge == 16 Put "Drive"; elseif userAge == 18 Put
"Vote"; elseif userAge == 21 Put "Drink"; else Put "Kid". What is output if userAge is 19?
Kid
A countdown program iterates: i = 0; while i < 12; i = i + 1. How many times will the loop
iterate?
12
A programmer writes a counter: x = 1; while x != 10; Put x; x = x + 4. What is the result of
running this code?
Infinite loop (x skips over 10)
A program prints a grid of coordinates: row = 0; while row < 2; col = 0; while col < 3; Put row,
col, " "; col = col + 1; row = row + 1. What is the output?
00 01 02 10 11 12
A program collects user input until the user enters -1. Write the loop expression.
userNum != -1
A program counts iterations: for i = 0; i < 4; i = i + 1; Put i; Put " ". What is the output?
0123
A chatbot keeps asking for user input until the user types "quit". Which control structure
should be used?
While loop
Correct Answers
A vending machine starts with 7 sodas. After restocking, the code runs: x = 7; x = x + 3. What is
the final value of x?
10
A warehouse tracks pallets. The code runs: y = 4; z = y * 2; y = y + z. What is the final value of
y?
12
A programmer names a variable "3rdPlace" to store a contestant's ranking. Is "3rdPlace" a
valid identifier?
No (starts with a digit)
A programmer names a variable "_userName" to store the username. Is "_userName" a valid
identifier?
No (must start with a letter)
A program tracks the number of windows in a house. Which is the best identifier?
numWindowsHouse
A student writes "2y" to mean "two times y" in an expression. Is "2y" a valid expression?
No (missing multiplication operator)
A program evaluates the expression a - b * c. Which operator is evaluated first?
*
A program evaluates m + 2 * n / 4. Which parenthesization matches the actual evaluation
order?
m + ((2 * n) / 4)
An inventory program runs: numItems = 4; totCount = 3 + (2 numItems) 5. What is the value
of totCount?
, 43
A programmer tries to name a loop counter "while". Is "while" a valid identifier?
No (reserved word)
A program needs to compute "5 more than triple x". Which expression correctly captures
this?
(3 * x) + 5
A shipping company charges: "Too heavy" if weight > 200, "Warning" if weight > 180, else
"OK". Which if statement type is needed?
If-elseif
An age permissions program runs: if userAge == 16 Put "Drive"; elseif userAge == 18 Put
"Vote"; elseif userAge == 21 Put "Drink"; else Put "Kid". What is output if userAge is 19?
Kid
A countdown program iterates: i = 0; while i < 12; i = i + 1. How many times will the loop
iterate?
12
A programmer writes a counter: x = 1; while x != 10; Put x; x = x + 4. What is the result of
running this code?
Infinite loop (x skips over 10)
A program prints a grid of coordinates: row = 0; while row < 2; col = 0; while col < 3; Put row,
col, " "; col = col + 1; row = row + 1. What is the output?
00 01 02 10 11 12
A program collects user input until the user enters -1. Write the loop expression.
userNum != -1
A program counts iterations: for i = 0; i < 4; i = i + 1; Put i; Put " ". What is the output?
0123
A chatbot keeps asking for user input until the user types "quit". Which control structure
should be used?
While loop