定义一个手机类, 具有打电话和录音的功能,打电话的时候可以录音,也可以不录音。
class MobilePhone(): def __init__(self,brand,type,color,phone_num): self.brand=brand #品牌 self.type=type #类型 self.color=color #颜色 self.phone_num=phone_num #手机号 def call(self): print('{}正在拨打电话...'.format(self.phone_num)) try: choice=int(input('请问您是否需要录音? 输入1(录音),输入2(不录音):')) if choice==1: self.record() elif choice==2: print('您未进入录音模式,请放心使用!') else: while True: print('