Please complete the code below:
main.py
from Instrument import Instrument
from StringInstrument import StringInstrument
import globals
import csv
class KeyboardInstrument(Instrument):
########################################################################
# Task 1 - define the constructor __init__
# NOTE: this must call the base class constructor
# parameters name:str, manufacturer:str, year_built:int, cost:int, num_keys:int, keyboard_type:str
########################################################################
def __init__(): # Fix this
#
# your code goes here
#
########################################################################
# Task 2 - complete this method
# NOTE: this must use the format_instrument method of the base class (Instrument)
# format_instrument_info(self) -> str
########################################################################
def format_instrument_info(self):
#
# your code goes here
#
return 'None' # Fix this
# ########################################################################
# Task 3 - complete this function
# read_instrument_objects(file_name: str) -> list[Instrument | StringInstrument | KeyboardInstrument]
########################################################################
def read_instrument_objects(file_name):
#
# your code goes here
#
return [] # Fix this
# ########################################################################
# Task 4 - complete this function
# most_expensive_instrument(instrument_objects: list[Instrument | StringInstrument | KeyboardInstrument])
# -> Instrument | StringInstrument | KeyboardInstrument
########################################################################
def most_expensive_instrument(instrument_objects):
#
# your code goes here
#
return None # Fix this
#######################################################################
# The following code is provided as a starting point for development and testing
# Please modify the code below as you develop your program.
#
# NOTE: you can submit WITH or WITHOUT the following main included
#######################################################################
# if __name__ == "__main__":
# globals.initialise_call_count()
# ins1 = Instrument('Drums','Zildjian',2015,2500)
# ins2 = Instrument('piano','steinway',1800,450000)
# ins3 = StringInstrument('Guitar','Gibson',2002,1200,6,19)
# ins4 = StringInstrument('Ukulele','Kala',2018,50,6,12)
# ins5 = KeyboardInstrument('piano','steinway',1700,500000,88,'grand')
# ins6 = KeyboardInstrument('Piano','yamaha',2010,2000,88,'electric')
#######################################################################
# Test code for Task 1, 2 - class constructor and method
#######################################################################
# print(ins5.format_instrument_info())
#######################################################################
# Test code for Task 3 - function read_instrument_objects
#######################################################################
# instrument_object_list = read_instrument_objects('instrument_info.csv')
# print('INSTRUMENT LIST')
# for ins in instrument_object_list:
# print(ins.format_instrument_info())
#######################################################################
# Test code for Task 4 - most_expensive_instrument
#######################################################################
# most_expensive = most_expensive_instrument([ins1, ins2, ins3, ins4, ins5, ins6])
# print('MOST EXPENSIVE:')
# print(most_expensive.format_instrument_info())
globals.py
def initialise_call_count():
global global_call_count
global_call_count = 0
def get_call_count():
return global_call_count
def increment_call_count():
global global_call_count
global_call_count += 1
instrument.py
import globals
class Instrument:
def __init__(self, name, manufacturer, year_built, cost):
globals.increment_call_count() # DO NOT touch this line
self.name = name
self.manufacturer = manufacturer
self.year_built = year_built
self.cost = cost
def format_instrument_info(self):
globals.increment_call_count() # DO NOT touch this line
info_str = ''
info_str += 'Instrument Information:\n'
info_str += f'Name: {self.name}\n'
info_str += f'Manufacturer: {self.manufacturer}\n'
info_str += f'Year built: {self.year_built}\n'
info_str += f'Cost: {self.cost}\n'
return info_str
StringInstrument.py
from Instrument import Instrument
class StringInstrument(Instrument):
def __init__(self, name, manufacturer, year_built, cost, num_strings, num_frets):
super().__init__(name, manufacturer, year_built, cost)
self.num_strings = num_strings
self.num_frets = num_frets