A workshop permits integer group sizes from 1 through 16. Its Python validator is:
def validate_group(quantity): if quantity < 1: raise ValueError("quantity must be positive") if quantity > 16: raise ValueError("quantity exceeds the limit") return quantity
Select every change that preserves exactly which integer inputs cause an exception to be raised. Compare exception occurrence only; the exception messages need not match.
Replace each raise keyword with return, keeping the existing exception constructors and messages unchanged.
Reverse the order of the two guards, keeping each condition and its raising statement unchanged.
Replace both guards with if quantity < 1 and quantity > 16:, whose body raises ValueError.
Replace both guards with if not (1 <= quantity <= 16):, whose body raises ValueError.
Unlock full course notes by signing up
Follow a failure through a caller
A theatre calculates remaining seats with the following Python functions. All quantities are integer seat counts, and neither function handles exceptions.
What happens when reserve_two(12) is evaluated?
Inspect state after raising
A booking program uses the following Python code. The list audit records attempted sales, including rejected attempts.
An external test harness runs the module's top-level code, catches the exception raised by the last line, and then inspects the variables without changing them. Find the stored value of stock, in seats, and the number of entries in audit. Enter both answers as exact integers.
Prioritize overlapping rejections
A warehouse reserves items in complete cartons of six. The following Python function receives integer quantities measured in individual items; stock is nonnegative.
Give both requested answers:
The exact exception message from reserve(25, 20), without quotation marks.
Evaluate the object supplied to raise
A Python inventory checker calls reject_order to signal a rejected request. Its helper either constructs a shortage exception or raises an exception about invalid stock data. All quantities are integer item counts.
For each independent call, enter the exact exception message without quotation marks. Also enter the name of the function that directly raises the reported exception: make_problem or reject_order. Constructing or returning an exception object does not count as raising it.