Recover from a malformed measurement tuple

A technician's program stores three cable lengths in metres. The first assignment unpacks a grouped measurement record. The next assignment attempts to replace those measurements.


Python raises a ValueError when an unpacking level has the wrong number of values. The except block catches that error; pass performs no action, and execution continues after the block.


Python
short, (middle, long) = (5, (8, 11))

try:
    short, middle, long = (13, 17)
except ValueError:
    pass

total = short + middle + long
spread = long - short


Determine the final values of total and spread. Enter both in metres as exact integers.

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 Tuples Questions: