Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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())
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts Of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

4th Edition

0619064625, 978-0619064624

More Books

Students also viewed these Databases questions

Question

Prepare a constructive performance appraisal.

Answered: 1 week ago

Question

List the advantages of correct report formatting.

Answered: 1 week ago