Boss

Boss: The Route Calculator

The boss
Boss Fight!
Every passing test breaks a shield.

The ferry master of Pythonia needs a Route Calculator before the evening crossings begin. Bridges connect some islands, and each has a length in km stored in BRIDGES. A bridge works in both directions: ("Ember", "Mist") also connects Mist to Ember.

Assignment

Write four functions. Use each one inside the next!

  1. distance(a, b) returns the length of the bridge between islands a and b, checking both orders. Returns None if there's no bridge.
  2. route_length(route) takes a list of islands, like ["Ember", "Mist", "Coral"], and returns the total km of every leg (here 4 + 7 = 11). A one-island route is 0. If any leg has no bridge, return None.
  3. fuel_needed(km, per_km=2, reserve=5) returns km * per_km + reserve.
  4. plan_trip(route, per_km=2) returns a summary string:
    • "Ember -> Mist -> Coral: 11 km, 27 fuel"
    • or, if the route is broken, "Ember -> Thorn: no bridge!"

" -> ".join(route) builds the arrow part for you.