June 2017
Beginner
352 pages
8h 39m
English
To the Flight class we add a new method make_boarding_cards() which accepts a card_printer:
class Flight: # ... def make_boarding_cards(self, card_printer): for passenger, seat in sorted(self._passenger_seats()): card_printer(passenger, seat, self.number(), self.aircraft_model())
This tells the card_printer to print each passenger, having sorted a list of passenger-seat tuples obtained from a _passenger_seats() implementation detail method (note the leading underscore). This method is in fact a generator function which searches all seats for occupants, yielding the passenger and the seat number as they are found:
def _passenger_seats(self): """An iterable series of passenger seating allocations.""" row_numbers, ...
Read now
Unlock full access