ITPEC FE Subject B April 2026 Question 2
ITPEC FE Subject B April 2026 — Question 2 of 20
b, b, d — the first if is a separate statement, so the second one overwrites whatever it assigned.
That separation is the specification bug the question warns about: a score above 90 is set to "a" and then immediately re-set to "b", because 90 is also above 70.
Trace each call:
- •
f(92)—retvarstarts"w";92 > 90sets"a"; the secondifthen finds92 > 70and overwrites with "b" - •
f(72)—72 > 90is false;72 > 70sets "b" - •
f(-10)— both> 90and> 70fail,> 60fails, and≤ 60is true, giving "d"
Answer (d)
Why not others:
- (a) and (b) and (c) — all answer "a" for f(92), which would be correct only if the grade branches formed one chain; here the second if runs unconditionally
- (e) and (f) — give "c" for f(72), using the > 60 branch even though > 70 matched first and elseif stops the chain
- (c) and (f) — return the initial "w" for f(-10), missing that -10 ≤ 60 is true, so the last branch does fire
Key rule: Separate if statements each execute; only elseif makes them exclusive. When a variable is assigned twice, the last assignment wins.
AI-generated — may contain errors
The original exam layout is preserved in the image so diagrams, formulas, tables, and code remain accurate.
This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.