# 定义一个“曲调类”Note,value属性表示声音的高低 # a. Note的三个子类分别表示高音、低音和中音 # b. 定义一个“乐器类”Instrument # c. 具有play()方法 # d. 子类: # i. “管乐器类”Wind # ii. “敲击乐器类”Percussion # iii. “弦乐器类”Singed # e. 只写一个方法传入乐器和音调实现: # i. 管乐器演奏中音 # ii. 弦乐器演奏高音 # iii. 敲击乐器演奏低音
class Note:
value=1
class LowNote(Note):
def __str__(self):
return '低音'
class Middle(Note):
def __str__(self):
return '中音'
class HighNote(Note):
def __str__(self):
return '高音'
class Instrument:
def play(self,note):
print(self,'演奏',note)
class Wind(Instrument):
def __str__(self):
return'管弦乐'
class Percussion(Instrument):
def __str__(self):
return '弦乐器'
class Singed(Instrument):
def __str__(self):
return '敲击乐器'
def show(instrument,note):
instrument.play(note)
wind=