0 of 6 problems solved • 0%

Exercise prompt

Locate a Seat

Example

A name lookup and a position lookup can fail for different reasons.

seats = {"A": ["Uma"]} try: print(seats["B"][0]) except KeyError: print("Unknown section") # printed here

Changing B to A makes the first lookup succeed. An index past the last seat would then raise IndexError.

Your task

Implement locate_seat(sections, section, index). Each section maps to a list of names. Return the name at the supplied nonnegative, zero-based index. Return "unknown section" for a missing key and "no seat" for an index beyond the list.

locate_seat({"A": ["Uma"]}, "A", 2) # "no seat"