Question: The airline.py program ( attached ) creates a dictionary of flights ( a mix of regular, business and first - class flights ) and displays

The
airline.py program (attached) creates a dictionary of flights (a mix of regular, business and
first-class flights) and displays their corresponding information. Flight information is provided
by the "airfare.txt", where flights are randomly upgraded or not to Business or FirstClass
flights. Write the missing code, in the #TODO locations of the classes Flight, Business and
FirstClass, in order for the program execution to display the details of flights stored in the
dictionary as illustrated by the sample output. Since the "points" and "meals" attributes for
Business and FirstClass objects are randomly assigned, every program run will yield different
values for these attributes. However, all other flight attributes will be the same for all program
executions, since the information is loaded from the same input file "airfare.txt".
Sample of expected program output using the "airfare.txt" file as input.
PLEASE ONLY FILL #TODO PART. PLEASE DO NOT MAKE ANY CHANGES TO OTHER PARTS OF THE CODE.
import random
class Flight:
def __init__(self,dtime,origin,destination,fare):
self.dtime = dtime
self.origin = origin
self.destination = destination
self.fare = fare
#TODO
class BusinessFlight(Flight):
def __init__(self,points,*args,**kwargs):
self.points = points
super (BusinessFlight,self).__init__(args,**kwargs)
#TODO
class Firstclass(Flight):
def __init__(self,meals,*args,**kwargs):
self.meals = meals
super (FirstClass,self).__init__(*args,**kwargs)
#TODO
def read_records(fname):
data = dict()
try:
with open(fnane,'r') as hd:
for line in hd:
f = line.split(',')
if len(f)!=4:
continue
f = line.split(',')
fare = float(f[3].strip()[1:])
dtime, origin, destination = f[0], f[1], f[2]
# Ungrade (randonly) to Business or First class
rd= int(fare)
nb = rd %3
if nb ==0:
mls = random.randint(1,4)
obj = Firstclass(mls,dtime, origin, destination, fare)
elif nb ==1:
pts = random.randint(10,rd)
obj = BusinessFlight(pts,dtime, origin, destination,fare)
else:
obj = Flight(dtime, origin, destination, fare)
data[dtime]= obj
except Exception as e:
print(e)
return data
data = read_records("airfares.txt")
dtimes = list(data.keys())
dtimes.sort()
for dt in dtimes():
print(data[dt].info())
 The airline.py program (attached) creates a dictionary of flights (a mix

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 Databases Questions!