Bus Route
Python
25 pts
Bus Route
A bus travels this route from Asmara to the west of Eritrea:
route = ["Asmara", "Keren", "Akordat", "Barentu", "Tesseney"]
Create these variables without typing any city names (use indexes, slices, len() and in):
start— the first stop, andend— the last stop.middle_stops— every stop except the first and the last. Use a slice with a negative end index so it would still work if the route were longer.has_keren— whether"Keren"is in the route.
Then print as shown. Expected output:
From Asmara to Tesseney ['Keren', 'Akordat', 'Barentu'] True
Checklist
- Keep the list
routeunchanged and do not type any city names in your new variables. - Create
start(the first stop) andend(the last stop). - Create
middle_stopswith a slice that uses a negative end index. - Create
has_keren, which tells whether"Keren"is in the route. - Print the
From ... to ...line, thenmiddle_stops, thenhas_keren.
🔑 Solution
If you view the solution before passing, you earn half points for this exercise. You still need to type it and press Check to finish.
How it works, step by step
Point at a step to highlight its lines. Type the solution yourself and press Check answer to finish.
