Answered step by step
Verified Expert Solution
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
firstclass 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 initselfdtime,origin,destination,fare:
self.dtime dtime
self.origin origin
self.destination destination
self.fare fare
#TODO
class BusinessFlightFlight:
def initselfpoints,argskwargs:
self.points points
super BusinessFlightselfinitargskwargs
#TODO
class FirstclassFlight:
def initselfmeals,argskwargs:
self.meals meals
super FirstClassselfinitargskwargs
#TODO
def readrecordsfname:
data dict
try:
with openfnaner as hd:
for line in hd:
f line.split
if lenf:
continue
f line.split
fare floatfstrip:
dtime, origin, destination f f f
# Ungrade randonly to Business or First class
rd intfare
nb rd
if nb :
mls random.randint
obj Firstclassmlsdtime, origin, destination, fare
elif nb :
pts random.randintrd
obj BusinessFlightptsdtime, origin, destination,fare
else:
obj Flightdtime origin, destination, fare
datadtime obj
except Exception as e:
printe
return data
data readrecordsairfarestxt
dtimes listdatakeys
dtimes.sort
for dt in dtimes:
printdatadtinfo
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started