code a flight listing software
- User
code a flight listing software
Assistant
Certainly! Below is a simplified example of a flight listing software using Python. This example will include basic features such as listing flights, searching for flights, and adding new flights. For simplicity, we'll use a list to store the flight data.
Flight Listing Software in Python
class Flight: def __init__(self, flight_number, departure_airport, arrival_airport, departure_time, arrival_time, price): self.flight_number = flight_number self.departure_airport = departure_airport self.arrival_airport = arrival_airport self.departure_time = departure_time self.arrival_time = arrival_time self.price = price def __str__(self): return (f"Flight {self.flight_number}: {self.departure_airport} to {self.arrival_airport} " f"Departure: {self.departure_time} Arrival: {self.arrival_time} Price: ${self.price}") class FlightListingSystem: def __init__(self): self.flights = [] def add_flight(self, flight): self.flights.append(flight) print(f"Flight {flight.flight_number} added successfully.") def list_flights(self): if not self.flights: print("No flights available.") for flight in self.flights: print(flight) def search_flights(self, departure_airport=None, arrival_airport=None): results = [flight for flight in self.flights if (not departure_airport or flight.departure_airport == departure_airport) and (not arrival_airport or flight.arrival_airport == arrival_airport)] if not results: print("No flights found.") for flight in results: print(flight) def main(): flight_system = FlightListingSystem() # Adding some sample flights flight_system.add_flight(Flight("AA123", "JFK", "LAX", "2023-10-01 08:00", "2023-10-01 11:00", 300)) flight_system.add_flight(Flight("BA456", "LAX", "JFK", "2023-10-01 14:00", "2023-10-01 17:00", 350)) flight_system.add_flight(Flight("DL789", "JFK", "MIA", "2023-10-01 10:00", "2023-10-01 12:00", 250)) while True: print("\nFlight Listing System") print("1. List all flights") print("2. Search for flights") print("3. Add a new flight") print("4. Exit") choice = input("Enter your choice: ") if choice == '1': flight_system.list_flights() elif choice == '2': departure_airport = input("Enter departure airport (or press Enter to skip): ") arrival_airport = input("Enter arrival airport (or press Enter to skip): ") flight_system.search_flights(departure_airport, arrival_airport) elif choice == '3': flight_number = input("Enter flight number: ") departure_airport = input("Enter departure airport: ") arrival_airport = input("Enter arrival airport: ") departure_time = input("Enter departure time (YYYY-MM-DD HH:MM): ") arrival_time = input("Enter arrival time (YYYY-MM-DD HH:MM): ") price = float(input("Enter price: ")) new_flight = Flight(flight_number, departure_airport, arrival_airport, departure_time, arrival_time, price) flight_system.add_flight(new_flight) elif choice == '4': print("Exiting...") break else: print("Invalid choice. Please try again.") if __name__ == "__main__": main()Explanation
- Flight Class: Represents a single flight with attributes like flight number, departure and arrival airports, times, and price.
- FlightListingSystem Class: Manages a list of flights and provides methods to add, list, and search flights.
- Main Function: Provides a simple text-based user interface to interact with the
FlightListingSystem.
Running the Code
- Copy the code into a Python file (e.g.,
flight_listing.py). - Run the file using Python (
python flight_listing.py). - Follow the prompts to list, search, or add flights.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.