
Boss
Boss: The Route Calculator

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!
distance(a, b)returns the length of the bridge between islandsaandb, checking both orders. ReturnsNoneif there's no bridge.route_length(route)takes a list of islands, like["Ember", "Mist", "Coral"], and returns the total km of every leg (here4 + 7 = 11). A one-island route is0. If any leg has no bridge, returnNone.fuel_needed(km, per_km=2, reserve=5)returnskm * per_km + reserve.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.
Write four functions. Use each one inside the next!
distance(a, b)returns the length of the bridge between islandsaandb, checking both orders. ReturnsNoneif there's no bridge.route_length(route)takes a list of islands, like["Ember", "Mist", "Coral"], and returns the total km of every leg (here4 + 7 = 11). A one-island route is0. If any leg has no bridge, returnNone.fuel_needed(km, per_km=2, reserve=5)returnskm * per_km + reserve.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.
main.py Python sleeping
Press Run to try your code, then Check to test it.