Modify the Shortest Flight program and write a new function that asks the user f
ID: 3544150 • Letter: M
Question
Modify the Shortest Flight program and write a new function that asks the user for the maximum flight duration and maximum price he/she is willing to pay and finds all flights that meet these criteria. So, for instance, the user could ask for all flights that are shorter than 6 hours and less than $300.
You may use the code below as a starting point:
https://www.dropbox.com/s/ww9do7j0qrtq0j6/Flights.py
and the data file can be found here:
https://www.dropbox.com/s/z05vprpkoyakc2l/flights.txt
Note, the price for flights is stored as a string with a
Explanation / Answer
def maxtime_maxpri():
maxtime=input("Enter the maxmium time you wish to travel for(in minutes): ")
maxpri=input("Enter the maxmium price you wish to pay(in $): ")
flights, departures, arrivals, prices = getData()
for i in range(len(departures)):
timetaken= computeDuration(departures[i],arrivals[i])
if prices[i]<=maxpri and timetaken<=maxtime:
print("Flight ", flights[i] ," Departure ", departures[i],"Arrival ", arrivals[i],"Price ",prices[i], "Duration ",time_taken[i] )
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.