Stop at the first failed check

A loading simulation runs this Python code with assertions enabled and no failure handling. Each number in masses is a parcel mass in kilograms. What is total when the first assertion fails? Answer in kilograms as an exact integer.


Python
masses = [6, 9, 8, 4]
total = 0

for mass in masses:
    total += mass
    assert total <= 20, "load exceeds limit"

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 Exceptions and Assertions Questions: