Back

Pseudocode Challenge: Decisions

divider

Objective

Three problems on selection. Two ask you to trace exam notation and say exactly what appears on the screen; one asks you to translate a Lua chain into notation that has no elseif.

Do this on paper. There is nothing to run and nothing to type. On exam day you get this notation on a printed sheet and no computer, so practicing it any other way practices the wrong thing.


Reference Card

Everything you need for this page. This is the same notation the College Board uses on the exam.

Exam Notation — what you have so far
a ← expression assign a copy of the result to a
DISPLAY(expression) show the value, FOLLOWED BY A SPACE
INPUT() take a value from the user
+ - * / 17 / 5 is 3.4 (no truncation)
a MOD b remainder. 17 MOD 5 is 2
RANDOM(a, b) whole number from a to b, BOTH INCLUDED
= ≠ > < ≥ ≤ comparison. = means EQUALS
NOT / AND / OR boolean operators
IF(condition) no ELSE IF exists - nest an IF inside an ELSE
{ ... }
ELSE
{ ... }

Two things catch people every time. DISPLAY puts a space after whatever it shows, so two DISPLAY calls in a row give you A B on one line — not two lines and not AB. And = means equals here, not assignment. Assignment is .


The Problems


Problem 1 — trace

What does this display?

Problem 1
temp ← 55
IF(temp > 70)
{
DISPLAY("Warm")
}
ELSE
{
DISPLAY("Cool")
}
DISPLAY("Reading done")

Problem 2 — trace

What does this display?

Problem 2
a ← 8
b ← 8
IF(a = b)
{
DISPLAY("same")
}
ELSE
{
DISPLAY("different")
}

Then answer this: a student says line 4 changes a to 8. Explain in one sentence why they are wrong.

And this. Here is what that student was thinking of, written in Lua. Say what happens when you run it, and why the exam notation cannot make the same mistake:

Problem 2, continued
local a = 8
local b = 8
if a = b then
print("same")
end

Problem 3 — translate

Rewrite this in exam notation. Remember: the reference sheet has no ELSE IF, so a chain has to be built out of nested IF and ELSE blocks.

Problem 3
local speed = 45
if speed > 70 then
print("Too fast")
elseif speed > 40 then
print("Fine")
else
print("Too slow")
end

Lua gives you elseif and the exam does not. That is one of the six places the two disagree, and the translation is where you feel it.


Submit

Your three answers, plus the two short explanations from problem 2. For the traces, write the output exactly as it appears, including spacing.

Worth 3 points, graded on completion. Show your working for the traces — a wrong answer with visible reasoning is worth more to both of us than a right one with none.

Commence Challenge