class SweetPotato(): def __init__(self): self.cook_time = 0 # 被烤的时间 self.cook_state = '生的' # 烤的状态 self.condiments = [] # 调料列表 def cook(self,time): self.cook_time += time if 0 <= self.cook_time < 3: self.cook_state= '生的' elif 3 <= self.cook_time < 5: self.cook_state= '半生不熟' elif 5 <= self.cook_time < 8: self.cook_state= '熟了' elif self.cook_time >= 8: self.cook_state = '烤糊了' def add_condiments(self,condiment): self.condiments.append(condiment) def __str__(self): return f'这个地瓜烤了{self.cook_time}分钟,状态是{self.cook_state},添加的调料有{self.condiments}' digua1 = SweetPotato() print(digua1) digua1.cook(2) digua1.add_condiments('大葱明') print(digua1) digua1.cook(2) digua1.add_condiments('大辣娇') print(digua1) digua1.cook(2) print(digua1) digua1.add_condiments('大糊咖') print(digua1) digua1.cook(2) print(digua1)
教你如何烤地瓜!!!
最新推荐文章于 2024-05-27 17:00:50 发布