Bus Ticket Prices
Python
30 pts
Bus Ticket Prices
A bus from Asmara to Massawa has these fares:
- Under 5 years old: 0 Nakfa
- 5 to 17 years old: 30 Nakfa
- 60 years or older: 40 Nakfa
- Everyone else (adults): 60 Nakfa, but adult students pay 20 Nakfa less
Each passenger is a tuple (name, age, is_student). Loop through passengers, work out each fare with if/elif/else (use a nested if for the student discount), store it in a dictionary called fares (name → fare), and print one line per passenger. Finally print the total of all fares.
Expected output:
Selam: 0 Nakfa Abel: 30 Nakfa Merhawi: 40 Nakfa Tesfay: 40 Nakfa Lidya: 60 Nakfa Total: 170 Nakfa
Checklist
- Create the dictionary
faresand fill it inside a loop overpassengers. - Give young children and passengers aged 5 to 17 the right fares.
- Give older passengers and adults the right fares, with the student discount for adults only.
- Print one line per passenger, then the total.
🔑 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.
