class SweetPotato:
def __init__(self):
self.cookedLevel=0
self.cookedString="生的"
self.contiments=[]
def __str__(self):
x="地瓜目前是{},包含的佐料有{}".format(self.cookedString,self.contiments)
return x
def cook(self,times):
self.cookedLevel+=times
if self.cookedLevel>8:
self.cookedString="焦的"
elif self.cookedLevel>5:
self.cookedString = "熟的"
elif self.cookedLevel>3:
self.cookedString="半生不熟的"
else:
self.cookedString = "生的"
def addcondiments(self,condiment):
self.contiments.append(condiment)
digua=SweetPotato()
print(digua)
digua.cook(1)
print(digua)
digua.addcondiments("芥末酱")
print(digua)
class SweetPotato:
def __init__(self):
self.cookedLevel=0
self.cookedString="生的"
self.condiments=[]
def __str__(self):
x="地瓜目前是{}".format(self.cookedString)
x+="需要添加的佐料有:{}".format(self.condiments)
return x
def cook(self,times):
self.cookedLevel+=times
if self.cookedLevel>8:
self.cookedString="焦的"
elif self.cookedLevel>5:
self.cookedString="熟的"
elif self.cookedLevel>3:
self.cookedString="半生不熟的"
else:
self.cookedString="生的"
def addcondiments(self,condiment):
self.condiments.append(condiment)
digua=SweetPotato()
print(digua)
digua.cook(1)
digua.addcondiments("芥末酱")
print(digua)
class SweetPotato:
def __init__(self):
self.cookedLevel=0
self.cookedString="生的"
self.condiments=[]
def __str__(self):
x="地瓜目前是{}".format(self.cookedString)
if len(self.condiments)!=0:
x += "需要添加的佐料有:"
x+=",".join(self.condiments)
else:
x+="没有添加任何佐料"
return x
def cook(self,times):
self.cookedLevel+=times
if self.cookedLevel>8:
self.cookedString="焦的"
elif self.cookedLevel>5:
self.cookedString="熟的"
elif self.cookedLevel>3:
self.cookedString="半生不熟的"
else:
self.cookedString="生的"
def addcondiments(self,condiment):
self.condiments.append(condiment)
digua=SweetPotato()
print(digua)
digua.cook(1)
digua.addcondiments("芥末酱")
print(digua)
digua.addcondiments("番茄酱")
print(digua)