You are viewing a single comment's thread from:
RE: Payment for Coding done
Sample flight price data (You can replace this with your actual data)
flight_data = [
{"destination": "Paris", "date": "2023-09-01", "price": 500},
{"destination": "Paris", "date": "2023-09-02", "price": 480},
{"destination": "Paris", "date": "2023-09-03", "price": 520},
{"destination": "Paris", "date": "2023-09-04", "price": 490},
{"destination": "Paris", "date": "2023-09-05", "price": 510},
# Add more flight data here...
]
Function to recommend the best time to book a flight to a destination
def recommend_booking_time(flight_data, destination):
# Filter flight data for the specified destination
destination_data = [flight for flight in flight_data if flight["destination"] == destination]
Sort flight data by date
Calculate the average price for each month
Calculate the average price for each month
Find the month with the lowest average price
Example usage
destination = "Paris"
recommendation = recommend_booking_time(flight_data, destination)
print(recommendation)