Question: Fix the following code so it works properly with all the functions below python idle 3.5 here is the link to the data file to
Fix the following code so it works properly with all the functions below python idle 3.5
here is the link to the data file to run the program :
http://homepage.cs.uri.edu/~cingiser/csc110/assignments/flights.txt
Here are the programs instructions:
https://sakai.uri.edu/access/lessonbuilder/item/11693389/group/e3dbb580-16f5-490f-aff0-88f96032a87c/Programming%20Project/airline_flights_assignment-1.pdf
The program is provided below
#Description:
# In this program the user will have five informations on their flight from providence,RI # to Orland, FL. By searching using the name of the airline, with that infomration # user will be able to see Flight number, departure time, arrival time and Price
#Solution:
# The user will have 7 options to find the information they need for their flight # with using options 1. Flights on a particular Airline 2. Cheapest Flight # 3. Flights cheaper than a specified Price 4. Shortest Flight # 5. Flights departing within specified time range 6. Average price for specified airline # # Once user chooses an option the airline information appears
#Pseudocode:
#User enters data file name #Displays all 7 options to find flights for Providence to Orlando # User types in number # if Option 1 # - ask users to enter name of airline # - returns flight information # elif option 2 # - gives users the cheapest flight, and flight information # elif option 3 # - user eneters in price # - returns flights that our cheaper then price # elif option 4 # - user enters in a particular airline name # - returns flight information for the shortest flight # elif option 5 # - User to enter earlist time and latest time available for depature # - giviing the flight and airline information # elif option 6 # - user enters in airline name # - gives user the average prices # elif option 7 # - user can quit program # else the users gives an invaild option # -dispalys error message and allow user to try again # Prints users choices
#Function Design:
def menu(): print("Please choose one of the following options:") print("1 -- Find all flights on a particular airline") print("2 -- Find the cheapest flight") print("3 -- Find all flights less than a specified price") print("4 -- Find the shortest flight") print("5 -- Find all the flights that depart within a specified airline") print("6 -- Find the average price for a specified airline") print("7 -- Quit") choice = int(input("Choice :")) return choice
def readData(): airlines = [] flights = [] departures = [] arrival = [] price = [] #Ask user to eneter in file name fileName = input("Enter in data file:") #Reads the data of the file and sepreates information readFile = open(fileName, 'r') for line in readFile: #Seperates text into different lists line = line.strip() airline, flight, departure, arrivals,prices = line.split(',') #appending files to list airlines.append(airline) flights.append(flight) departures.append(departure) arrival.append(arrivals) prices.append(int(prices))
readFile.close() # return AirlineList, NameFlightList , departList, arrivalList, priceList
return(airlines,flights,depatures,arrival,price)
def display(airline, flights, departures, arrival, price, index): print("The flights that meet your criteria are:") print(' ') print("AIRLINE FLT# DEPT ARR PRICE") print("--------------------------------------------") for i in range(len(index)): departure = str(departures[index[i]]) arrival = str(arrivals[index[i]]) print(airlines[index[i]], flights[index[i]], departure, arrival, price[index[i]])
def index(airline, airlineName): #implenments index to add in display index = [] i = 0 while i
def cheapFlight(price): # Finds the cheapest flight from the list of flights cheap = prices[0] i = 0 j = 0 while i prices[i]: cheap = prices[i] j += 1 i += 1 #return NameofAirline, flightNum, price return def cheaperThanPrice(): i = 0 FlightIndex = [] #Function will ask user to enter a certain amount while i = prices[i]: FlightsIndex.append(i) i = i + 1 return(FlightIndex) #NameofAirline, flightNum, and shortFlight print(airlines, flight, arrival, price)
def shortFlight(airlines,flights): # Function will provide the user airlines and flight numbers for the user short = LengthFlight[0] i = 1 j = 0 # to check which has the shortest commute while i LengthFlight[i]: short = LengthFlight[i] j += 1 i += 1 return (short, j) #NameofAirline, flightNum, and shortFlight print(airlines, flight, arrival, price)
def departFlightTime(depart,start,end): # Function asks user to enter in their available time between earliest departIndex = [] departTime = [] #and latest time. Will provide user with name of airline, flight number starthour, startmin = start.split(':') endhour, endmin = end.split(':') startTime = starthour + startmin endTime = endhour + endmin for i in range(len(departures)): dHour, dMin = departures[i].split(':') departTime = dHour + dMin departTime.append(int(departTime)) j = 0
while j
def averageFlight(): #Function has user to enter in desired airLine total = 0 #User will be given the airline and the average price for i in range(len(index)): total = total + nums[index[i]] average = total/len(index) return(average) #NameofAirline, flightNum, times and averagePrice print(airlines, flight, arrival, price)
def main(): # The main function uses all functions above to create airplane displays airlines, flights, departures, arrival, prices = readData() LengthFlight = departFlightTime() while choice != 7: choice = menu() # show so the user can choose options and pick flights to attend for a better if (choice == 1): print('Enter name of airline from below') print(" ") print("USAir, JetBlue, UNITED, Delta") airlinename = input("Enter name of airline:") if airlineName != ("USAir, JetBlue, UNITED, Delta"): print("Invaild input -- try again") airlineMane = input("Enter name of airline:") index = index(airline, airlineName) display(airlines, flights, departures, arrival,price)
elif (choice == 2): print("The cheapest flight is", flights[cheapflight(price)], "at" ,price[cheapflight(price)]) elif (choice == 3): price = int(input("Enter your maximum price:")) display("Flight"(cheaperThanPrice(price), airlines, flights, departures,arrival, price)) elif (choice == 4): short, i = shortFlight(LengthFlight, flights) print("The shortest flight is", flight[i], "at",short[i],"minutes") elif (choice == 5): earliestTime = input("Enter the earliest allowable depature time:") latestTime = input("Enter the latest allowable departure time:") if start() or end(): print("Invaild time -- try again") earliestTime = input("Enter the earliest allowable depature time") latestTime = input("Enter the latest allowable departure time:") departIndex = departFlightTime(depart,start,end) display(airlines, flights,departures, arrival,price,departIndex) elif (choice == 6): airlineMame = input("Enter name of airline:") if airlineName != 'USAir' or 'JetBlue' or 'UNITED' or 'Delta': print("Invaild input -- try again") print("enter name of airline:") index = index(airlines, airlineName) average = averageFlight() print("The average price is:", average) elif (choice == 7): print("Thank you, come again!")
some of your output should look like this

a SakaieURI:csc 110. x airline fights assign. airline flights assign.. x a csc 110 Final Exam.. x M Ayy-joffrey dupaul.. x Q what tochniques can.. X E oakland Raidors draf.. X C Chogg studyIGuide. x http 'homa. lights. bt X https sakai. project/airine flights assignment-1 pdf e a, ode change A Most visited e Getting started t Automatic Zoom Shortest Flight Please choose one of the following options: 1 Find all flights on a particular airline 2 Find the cheapest flight 3 Find all flights less than a specified price 4 Find the shortest flight 5 Find all flights that depart within a specified range 6 Find the average price for a specified airline 7 Quit Choice 4 The shortest flight is JetBlue 1075 at 186 minutes Flights Departing Within Specified Time Range Please choose one of the following options Find all flights on a particular airline Find the cheapest flight Find all flights 1ess than a specified price Find the shortest flight 5 Find all flights that depart within a specified range 6 Find the average price for a specified airline Quit Choice Enter the earliest allowable departure time 1 1200 Invalid time try again Enter the t all ble departure time 12 100 Enter the latest allowable departure time: 15:00 The flights that meet your criteria are FILTA AIRLINE DEPT PRICE 217 UNITED 6001 4:12 20:50 Delta, 5054 2130 20122 227 USAir 300 2689 12:55 18:09 USAir 3609 13:25 18:28 302 Delta 3601 12:00 17:29 307 Average Price for S fied Airline a SakaieURI:csc 110. x airline fights assign. airline flights assign.. x a csc 110 Final Exam.. x M Ayy-joffrey dupaul.. x Q what tochniques can.. X E oakland Raidors draf.. X C Chogg studyIGuide. x http 'homa. lights. bt X https sakai. project/airine flights assignment-1 pdf e a, ode change A Most visited e Getting started t Automatic Zoom Shortest Flight Please choose one of the following options: 1 Find all flights on a particular airline 2 Find the cheapest flight 3 Find all flights less than a specified price 4 Find the shortest flight 5 Find all flights that depart within a specified range 6 Find the average price for a specified airline 7 Quit Choice 4 The shortest flight is JetBlue 1075 at 186 minutes Flights Departing Within Specified Time Range Please choose one of the following options Find all flights on a particular airline Find the cheapest flight Find all flights 1ess than a specified price Find the shortest flight 5 Find all flights that depart within a specified range 6 Find the average price for a specified airline Quit Choice Enter the earliest allowable departure time 1 1200 Invalid time try again Enter the t all ble departure time 12 100 Enter the latest allowable departure time: 15:00 The flights that meet your criteria are FILTA AIRLINE DEPT PRICE 217 UNITED 6001 4:12 20:50 Delta, 5054 2130 20122 227 USAir 300 2689 12:55 18:09 USAir 3609 13:25 18:28 302 Delta 3601 12:00 17:29 307 Average Price for S fied Airline
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
