forked from elviscgn/FlightBooking
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflight.py
More file actions
45 lines (31 loc) · 1.25 KB
/
flight.py
File metadata and controls
45 lines (31 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from passenger import Passenger
from exceptions import FlightFullError
class Flight:
def __init__(self, flight_number, origin, destination, capacity = 5):
self.flight_number = flight_number
self.origin = origin
self.destination = destination
self.capacity = capacity
self.booked_passengers = []
self.available_seats = capacity
def add_booking(self, passenger):
if self.is_full() == False:
self.booked_passengers.append(passenger)
else:
raise FlightFullError
if passenger in self.booked_passengers:
self.available_seats -= 1
def is_full(self):
if len(self.booked_passengers) >= self.capacity:
return True
elif self.capacity > len(self.booked_passengers):
return False
def __eq__(self, other):
return(
isinstance(other, self.__class__)
and self.flight_number == other.flight_number
)
def __str__(self):
return f"Flight number: {self.flight_number}, From: {self.origin}, To: {self.destination}, Seats: {self.available_seats}"
# f = Flight("ER202", "South Africa", "Nairobi", capacity = 4)
# print(f)