Question: 4 :Unit test Tests constructor Stringlnstrument ( ' Guitar ' , 'Gibson', 2 0 0 2 , 1 2 0 0 , 6 , 1

4:Unit test
Tests constructor Stringlnstrument('Guitar', 'Gibson', 2002,1200,6,19, False) sets my_string_instrument.num_strings =6
Your test produced
no output.
5:Unit test
Tests constructor Stringlnstrument('Guitar', 'Gibson', 2002,1200,6,22, False) sets my_string_instrument.num_frets =22
Your test produced
no output.
6:Unit test
Tests constructor StringInstrument('Viola', 'Yamaha', 2012,1200,4,0, True) sets my_string_instrument.is_bowed = True
Your test produced
no output.1
3
.
7
LAB: Instrument information
(
derived classes
)
Given the base class Instrument, define a derived class StringInstrument for string instruments with a constructor that initializes the attributes of the Instrument class as well as new attributes of the following types
integer to store the number of strings
integer to store the number of frets
boolean to store whether the instrument is bowed
Ex
.
If the input is:
Drums
Zildjian
2
0
1
5
2
5
0
0
Guitar
Gibson
2
0
0
2
1
2
0
0
6
1
9
False
the output is:
Instrument Information:
Name: Drums
Manufacturer: Zildjian
Year built:
2
0
1
5
Cost:
2
5
0
0
Instrument Information:
Name: Guitar
Manufacturer: Gibson
Year built:
2
0
0
2
Cost:
1
2
0
0
Number of strings:
6
Number of frets:
1
9
Is bowed: False
Here is my code and the error that I am recieving: class Instrument:
def __init__(self, name, manufacturer, year_built, cost):
self.name = name
self.manufacturer = manufacturer
self.year_built = year_built
self.cost = cost
def print_info(self):
print(f"Instrument Information:")
print(f"Name: {self.name}")
print(f"Manufacturer: {self.manufacturer}")
print(f"Year built: {self.year_built}")
print(f"Cost: {self.cost}")
class StringInstrument(Instrument):
def __init__(self, name, manufacturer, year_built, cost, num_strings, num_frets, is_bowed):
super().__init__(name, manufacturer, year_built, cost)
self.num_strings = num_strings
self.num_frets = num_frets
self.is_bowed = is_bowed
def print_info(self):
super().print_info()
print(f"Number of strings: {self.num_strings}")
print(f"Number of frets: {self.num_frets}")
print(f"Is bowed: {self.is_bowed}")
# Read input
instrument_name = input()
instrument_manufacturer = input()
instrument_year_built = int(input())
instrument_cost = int(input())
string_instrument_name = input()
string_instrument_manufacturer = input()
string_instrument_year_built = int(input())
string_instrument_cost = int(input())
string_instrument_num_strings = int(input())
string_instrument_num_frets = int(input())
string_instrument_is_bowed = input()== "True"
# Create Instrument object
instrument = Instrument(instrument_name, instrument_manufacturer, instrument_year_built, instrument_cost)
# Create StringInstrument object
string_instrument = StringInstrument(string_instrument_name, string_instrument_manufacturer, string_instrument_year_built, string_instrument_cost, string_instrument_num_strings, string_instrument_num_frets, string_instrument_is_bowed)
# Print information
instrument.print_info()
print()
string_instrument.print_info()
 4:Unit test Tests constructor Stringlnstrument('Guitar', 'Gibson', 2002,1200,6,19, False) sets my_string_instrument.num_strings =6

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!