Edit exercise.py. All spot and vehicle identifiers are nonempty strings. Kinds are exactly motorcycle, car, and van, ranked in that order. Invalid identifiers or kinds raise ValueError before mutation.

Prototype: implement choose_spot(spots, vehicle_kind). spots is a list of (spot_id, kind) pairs with unique identifiers; every listed spot is free. Return the selected spot identifier or None. Use smallest compatible kind, then lexicographic identifier. Do not change the input. Validate every spot, including spots that cannot be selected; duplicate spot identifiers raise ValueError.

Final: implement ParkingLot(spots) with the same inventory validation; an empty inventory is valid. park(vehicle_id, kind) returns a fresh ticket dictionary with keys ticket_id, vehicle_id, vehicle_kind, and spot_id, or None if no compatible spot is free. Ticket numbers start at 1 and advance only on success. A vehicle with an active ticket raises ValueError; after release it may park again. release(ticket_id) accepts an integer identifier and returns the released ticket as a fresh dictionary, or None for an unknown or already released identifier. active_tickets() returns fresh dictionaries in a fresh list ordered by ticket number. available_spots() returns a fresh list of (spot_id, kind) tuples ordered by kind rank, then identifier. Separate lots own separate state. Invalid requests and capacity failures leave state and the next ticket number unchanged.

Drag or use the arrow keys to resize. Home collapses the question; End collapses the editor. Enter or double-click resets the split.
Loading editor…
No results yet.

Complete the starter code, then run the checks.
Results and errors will appear here.