ITPEC FE Subject B April 2026 Question 2
From the answer group below, select the correct combination of answers to be inserted into A through C in the description.
Function f receives an integer value as argument argval and returns the grade character. The return value of f(, f(, and f( are “A,” “B,” and “C,” respectively. Note that the function has a specification bug.
Answer group
Explanation
A: b, B: b, C: d — the first if is a separate statement, so for 92 the second if overwrites the "a" it assigned.
That is the specification bug: every value above 90 is also above 70, so "a" can never survive.
- •
f(—92) retvarstarts as"w"; 92 > 90 sets"a"; the secondifthen finds 92 > 70 and overwrites it with"b" - •
f(— 72 > 90 is false; 72 > 70 sets72) "b" - •
f(— every-10) >test fails, and the last branch, −10 ≤ 60, sets"d"
Answer (d)
Why not others:
- •(a), (b) and (c) — give
"a"forf(, as if the two92) ifstatements formed one chain; the secondifstill runs and overwrites it - •(e) and (f) — give
"c"forf(, but 72 > 70 matches first and72) elseifstops the chain before the> 60test - •(c) and (f) — also give
"w"forf(, missing that the final-10) elseif (argval ≤ 60)is true for −10, so the default is replaced
Key rule: Consecutive if statements are tested independently and a later match overwrites an earlier one; only elseif makes branches exclusive.
Math & Numbers · AI-written, may contain errors
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.