ITPEC FE Subject B April 2024 Question 2
From the answer group below, select the correct answer to be inserted into blank in the program.
A bus company operates buses between two cities. The standard ticket price is 20 US dollars and the discount ticket price for passenger aged 10 and under or aged 60 and over is 10 US dollars. Additionally, registered members of all ages always get the ticket at the discount price.
The function ticketPrice receives the arguments age (a non-negative integer value) and isMember (a boolean indicating that the passenger is a member if the value is true), which returns the value ret as the ticket price (in US dollars).
Answer group
Explanation
((age ≤ 10) or (age ≥ 60)) or isMember — any one of the three conditions earns the 10-dollar price, so all three are joined with or.
The discount goes to three groups: passengers aged 10 and under, passengers aged 60 and over, and members of any age. Belonging to any one of them is enough, so the conditions are combined with or. Note also that no age is both at most 10 and at least 60, so (age ≤ 10) and (age ≥ 60) is always false.
Check: age 8 non-member, age 65 non-member and age 35 member all get 10; only age 35 non-member gets 20.
Answer (d)
Why not others:
- •(a) — the age part is always false, so the whole condition is false and every passenger pays 20
- •(b) — the age part is always false, so only members get the discount; a non-member aged 8 or 65 pays 20
- •(c) —
and isMemberdemands membership on top of the age rule: a non-member aged 65 pays 20, and so does a member aged 35
Key rule: When each condition on its own is enough to qualify, join them with or; a conjunction of disjoint ranges such as x ≤ 10 and x ≥ 60 can never be true.
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.