Separate requirements from enforced checks

A delivery service accepts packages weighing 1–2000 g inclusive. Assume every supplied weight is an integer. A reviewer compares the function’s docstring with its implementation, including calls outside the permitted range. Which finding correctly identifies a documentation discrepancy?


Python
def delivery_cost(weight_g):
    """Return delivery cost in cents.

    weight_g must be an integer from 1 to 2000 inclusive.
    Return 400 for weights up to 1000 g, otherwise 700.
    Raise ValueError for weights outside the permitted range.
    """
    if weight_g > 2000:
        raise ValueError("Too heavy")
    if weight_g <= 1000:
        return 400
    return 700
Choose an answer

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 Program Readability, Organization, and Documentation Questions: