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.


Python
def reserve(units, stock):
    if units > stock:
        raise ValueError("Insufficient stock")
    if units < 0 or units % 6 != 0:
        raise ValueError("Use nonnegative multiples of six")
    return stock - units


Give both requested answers:

  • The exact exception message from reserve(25, 20), without quotation marks.
  • The largest reservation quantity that returns normally when stock is 20 items. Answer in items as an exact integer.
Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Raising Exceptions Questions: