Project · Python Programming
Project: a train booking service
The brief
Build the core of a train booking service: checked passenger records, a fare rule with GST, a PNR generator, an audit decorator, a Train class that books and cancels seats, a reservation chart and a test that catches fare bugs.
Why it matters
Booking systems for trains, buses, flights and events all have this core: validated records, a price rule, unique reference numbers, seats that must never be double-booked, an audit trail and a printed chart. Back-end developers in travel and ticketing companies write and test exactly these pieces.
Skills you practise
- dataclasses and __post_init__
- properties
- custom exceptions
- generators
- decorators with functools.wraps
- classes and dunder methods
- writing tests that catch bugs
What you will have at the end
booking.py: a tested booking core (passengers, fares, PNRs, booking, cancelling, an audit log and a reservation chart) that you can walk an interviewer through.
How it is marked (rubric, 100 points)
| Correct behaviourAll eight checks pass: no double booking, no negative refunds, failed actions leave no trace. | 40 |
|---|---|
| Good Python designDataclasses for records, a class for state, a generator for PNRs and the chart, a decorator for the audit trail. | 25 |
| Errors that helpBad input raises ValueError, KeyError or NoSeatsError with a message that says what went wrong. | 15 |
| Tests that catch bugstest_fare() covers normal, AC and short-trip fares and fails for both broken versions. | 20 |
0/8 steps done
Step 1 of 8
A checked Passenger
Passenger strips spaces from the name, raises ValueError for an empty name or an age outside 0 to 125, and has an is_senior property (60 or over).
A dataclass writes __init__ for you. To check the values, add __post_init__: the dataclass calls it right after filling the fields. Raise ValueError for bad data, so a wrong record never gets into the system. A @property looks like a field (p.is_senior, no brackets) but is worked out from age each time, so it can never be out of date.
Run shows what your code prints. Check runs the step's tests. Ctrl+Enter checks too.