Question: Question 1 : Analyzing Flight Data for an Aviation Company Objective: The objective of this assignment is to introduce intermediate Python programming concepts such as

Question 1: Analyzing Flight Data for an Aviation Company
Objective: The objective of this assignment is to introduce intermediate Python programming concepts such as strings, functions, and lists. By the end of this assignment, you will be able to manipulate strings, create and use functions, and work with lists to solve a more complex problem related to analyzing flight data for an aviation company.
Scenario: You are a data analyst for an aviation company. The company operates multiple flights, and you need to analyze the flight data to provide insights. The program should be able to calculate the average (mean), median, and mode of flight durations, identify the flight with the longest duration, and categorize flights based on their duration.
Problem Statement: Write a Python program that:
Takes user input for a list of flight numbers and their corresponding durations (in minutes).
Calculates the average (mean) flight duration.
Calculates the median flight duration.
Calculates the mode of the flight durations.
Identifies the flight with the longest duration.
Categorizes flights into "Short-haul" (less than 3 hours), "Medium-haul" (3 to 6 hours), and "Long-haul" (more than 6 hours).
Prints the results in a formatted string.
Assumptions:
The user will provide the list of flight numbers and their corresponding durations.
Each flight has only one duration associated with it.
The list will contain at least one flight.
Instructions: (Optional to follow instructions!)
Define a function calculate_mean that takes a list of durations and returns the average (mean) duration.
Define a function calculate_median that takes a list of durations and returns the median duration.
Define a function calculate_mode that takes a list of durations and returns the mode duration. If there is no mode, print the entire list of durations.
Define a function find_longest_flight that takes a list of flight numbers and their corresponding durations, and returns the flight number with the longest duration. In case there are multiple flights with the same longest duration, return just the first longest flight
Define a function categorize_flights that takes a list of flight numbers and their corresponding durations, and returns a dictionary categorizing flights into "Short-haul", "Medium-haul", and "Longhaul".
Use user input to create the list of flight numbers and durations.
Call the defined functions to calculate the mean, median, mode, longest flight, and categorize flights, and print the results.
Deliverables:
A Python script that includes the defined functions and the main program logic.
The script should prompt the user for input and print the average (mean) duration, median duration, mode duration, the flight with the longest duration, and the categorized flights in a formatted string.
Page 2 of 8
Sample Output 1:
Enter the number of flights: 5
Enter flight number: CX001
Enter duration for flight CX001(in minutes): 500
Enter flight number: CX002
Enter duration for flight CX002(in minutes): 150
Enter flight number: CX003
Enter duration for flight CX003(in minutes): 300
Enter flight number: CX004
Enter duration for flight CX004(in minutes): 350
Enter flight number: CX005
Enter duration for flight CX005(in minutes): 60
Mean duration: 272.00 minutes
Median duration: 300.00 minutes
Mode duration:
[500.0,150.0,300.0,350.0,60.0] minutes
Longest flight: CX001
Categorized flights:
Short-haul: ['CX002','CX005']
Medium-haul: ['CX003','CX004']
Long-haul: ['CX001']
Sample Output 2:
Enter the number of flights: 5
Enter flight number: DXB01
Enter duration for flight DXB01(in minutes): 100
Enter flight number: DXB02
Enter duration for flight DXB02(in minutes): 300
Enter flight number: DXB03
Enter duration for flight DXB03(in minutes): 100
Enter flight number: DXB04
Enter duration for flight DXB04(in minutes): 400
Enter flight number: DXB05
Enter duration for flight DXB05(in minutes): 200
Mean duration: 220.00 minutes
Median duration: 200.00 minutes
Mode duration: 100.0 minutes
Longest flight: DXB04
Categorized flights:
Short-haul: ['DXB01','DXB03']
Medium-haul: ['DXB02','DXB05']
Long-haul: ['DXB04']
Page 3 of 8
Question 1 : Analyzing Flight Data for an

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!