Consider the following conditional code, which returns a Boolean values if…
2022
Consider the following conditional code, which returns a Boolean values
if ((𝑥 > 25)&&(𝑦 > 100))
return 'false';
else iff (𝑥 ≤ 25)&&&(𝑦 ≤ 100))
return 'true';
else iff (𝑥 > 25) && (𝑦 ≤ 100))
return 'false';
else
return 'true';
Simplify it by filling in the following blank with a single Boolean expression without changing the behaviour of the conditional code.
if (_ _ _ _ _ _ _ _ _)
return 'true';
else
return 'false';
- A.
𝑥 > 25
- B.
𝑥 ≤ 25
- C.
𝑦 > 100
- D.
𝑦 ≤ 100
Attempted by 318 students.
Show answer & explanation
Correct answer: B
Simplified condition: x ≤ 25
Reasoning:
Case 1: x > 25 and y > 100 → returns false (first branch).
Case 2: x > 25 and y ≤ 100 → returns false (third branch).
Case 3: x ≤ 25 and y ≤ 100 → returns true (second branch).
Case 4: x ≤ 25 and y > 100 → returns true (else branch).
Conclusion: For both values of y, the function returns true exactly when x ≤ 25 and returns false when x > 25. Therefore the conditional can be simplified to if (x ≤ 25) return true; else return false;.
A video solution is available for this question — log in and enroll to watch it.