runtime
258 / 500
question 258 Classes & Objects · medium

Seat bookings that keep their rules

Write a class Flight(code, seats) for a small booking system. Seats are numbered from 1. Booking gives a passenger the lowest free seat; a passenger can hold only one seat; a full flight refuses bookings; cancelling frees the seat for the next booking. All refusals raise ValueError and change nothing.

`Flight(code, seats)`seats is how many seats there are (at least 1, otherwise ValueError)
`book(passenger)`returns the seat number given; ValueError if the passenger already has a seat or the flight is full
`cancel_booking(passenger)`frees their seat; ValueError if they have none
`seat_of(passenger)`their seat number, or None
`available()`how many seats are free

Loading your progress…

Seat bookings that keep their rules — Python practice · Runtime