Musical Instruments

You are developing an application for managing a musical orchestra's instrument inventory. You have to model different types of musical instruments and their actions.
You are asked to create a MusicInstrument class that has two attributes: name and type. This class should also have a method play() that prints "Playing the instrument".
Then, create a Guitar class that inherits from the MusicInstrument class (Guitar is of type String. This should be set automatically from the __init__ of Guitar). This class should have a method tune() that prints "Tuning the guitar". The play() method in the Guitar class should first call the tune() method and then calls play() from the parent class using super().
Create a Violin class in the same way as the Guitar class (it’s also of type String).
Finally, create a Piano class that also inherits from the MusicInstrument class (Piano is of type Keyboard). The Piano class should override the play() method but it should not be tuned when played.
The program should create instances of the Guitar, Violin, and Piano classes, call their play() methods and display the correct statements on the console.
Input
Output
guitar = Guitar('Gibson'); violin = Violin('Stradivarius'); piano = Piano('Steinway'); guitar.play(); violin.play(); piano.play(); print(guitar.type); print(violin.type); print(piano.type)
Tuning the guitar Playing the instrument Tuning the violin Playing the instrument Playing the instrument String String Keyboard
Note: The instrument's name and type attributes should be passed as parameters to the class constructor during instantiation. The play() method should be called without any parameters.
 

Constraints

Time limit: 2 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue