Four problems on Boolean expressions. AND, OR and NOT are one of the few places the exam and Lua agree almost word for word — almost, and problem 3 is the exception.
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.
Everything you need for this page. This is the same notation the College Board uses on the exam.
a ← expression assign a copy of the result to aDISPLAY(expression) show the value, FOLLOWED BY A SPACEINPUT() take a value from the user
+ - * / 17 / 5 is 3.4 (no truncation)a MOD b remainder. 17 MOD 5 is 2RANDOM(a, b) whole number from a to b, BOTH INCLUDED
= ≠ > < ≥ ≤ comparison. = means EQUALSNOT / AND / OR boolean operators
IF(condition) condition is TRUE or FALSE. Nothing else.{ ... } no ELSE IF exists - nest an IF inside an ELSEELSE{ ... }Read NOT last and read it out loud. NOT (x < y) is not "x is greater than y" — it is "it is not the case that x is less than y", and the two are only the same answer when the values are different.
What does this display?
age ← 16hasPass ← false
IF(age ≥ 18 OR hasPass){ DISPLAY("Enter")}ELSE{ DISPLAY("Denied")}Then answer this: hasPass holds a value, and it is not being compared to anything. Say what kind of value it is and why OR accepts it on its own.
Three separate IF statements, one after another. What does this display?
x ← 12y ← 5
IF(NOT (x < y)){ DISPLAY("first")}IF(x > 10 AND y > 10){ DISPLAY("second")}IF(x > 10 OR y > 10){ DISPLAY("third")}Not all three run. Not none of them run either.
This is Lua, not exam notation. Write down exactly what it prints, then answer the question underneath.
local count = 0
if count then print("A")end
if count == 0 then print("B")endThe question: the first if is handed the number 0, not a comparison. Say what Lua does with it, and then say why there is no way to write that first if in exam notation at all.
IF takes a condition, and a condition on the exam is true or false. The sheet never says what IF(0) does because on the exam that cannot happen — and a habit you build in Lua will quietly follow you into May if nobody names it.RANDOM does not give one answer, so write down every value this could display.
n ← RANDOM(1, 4)DISPLAY(n * 2)The endpoints are the whole question. Check the reference card before you decide how many answers there are.
Your four answers, plus the two short explanations from problems 1 and 3. 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.