学这教程敲代码,运行不了
class SeP():
def __init__(self):
# 时间
self.cook_time = 0
# 状态
self.cook_sta = '生的'
# 调料
self.cnm = []
def cook(self, time):
self.cook_time += time
if 0 <= self.cook_time <= 3:
self.cook_sta = '生的'
elif 3 < self.cook_time <= 5:
self.cook_sta = '半生不熟'
elif 5 < self.cook_time <= 8:
self.cook_sta = '熟了'
elif 8 < self.cook_time:
self.cook_sta = '老了'
def __str__(self):
return f'这个地瓜被烤过的时间为{self.cook_time},状态是{self.cook_sta}'
dg1 = SeP()
print(dg1)
dg1.cook(3)
print(dg1)
AttributeError: 'SeP' object has no attribute 'cook_time'



