-
Notifications
You must be signed in to change notification settings - Fork 0
/
abc_airlines.py
50 lines (39 loc) · 1.78 KB
/
abc_airlines.py
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
46
47
48
49
50
class Flight:
def __init__(self, flight_number, departure_city, arrival_city, departure_time, seat_capacity=150):
self.flight_number = flight_number
self.departure_city = departure_city
self.arrival_city = arrival_city
self.departure_time = departure_time
self.seat_capacity = seat_capacity
self.passenger_list = []
def add_passenger(self, passenger_name):
if len(self.passenger_list) < self.seat_capacity:
self.passenger_list.append(passenger_name)
print(f"Passenger {passenger_name} added.")
else:
print("The flight is full.")
def remove_passenger(self, passenger_name):
if passenger_name in self.passenger_list:
self.passenger_list.remove(passenger_name)
print(f"Passenger {passenger_name} removed.")
else:
print(f"Passenger {passenger_name} is not on the flight.")
def log_flight(self):
with open("flight_log.txt", "a") as log_file:
log_file.write(f"{self.flight_number}, {self.departure_city}, {self.arrival_city}, {len(self.passenger_list)}\n")
print(f"Flight {self.flight_number} logged.")
def check_availability(self):
return self.seat_capacity - len(self.passenger_list)
def __repr__(self):
return (f"Flight {self.flight_number} from {self.departure_city} to {self.arrival_city}")
# Example usage:
flight = Flight("AB123", "New York", "London", "2024-06-24 18:00")
print(flight)
flight.add_passenger("Bhushan Thumsi")
flight.add_passenger("Lebron James")
print(f"Available seats: {flight.check_availability()}")
flight.remove_passenger("John Doe")
flight.remove_passenger("Lebron James")
print(f"Available seats: {flight.check_availability()}")
flight.log_flight()
print(flight)