烤地瓜

作者: 我是大笨蛋 | 来源:发表于2017-11-20 20:35 被阅读0次

    class SweetPotato:

    def __init__(self,cookedLevel=0,cookedString='生的',condiments=[]):

    #初始属性 烤的时间 程度 配料

    self.cookedLevel = cookedLevel

    self.cookedString = cookedString

    self.condiments = condiments

    def cook(self,Time):

    self.cookedLevel += Time

    if self.cookedLevel <=3:

    self.cookedString ='生的'

    elif self.cookedLevel <=5:

    self.cookedString ='半熟'

    elif self.cookedLevel <=8:

    self.cookedString ='熟了'

    else:

    self.cookedString ='木炭'

    def addCondiments(self,condiments):

    self.condiments += condiments

    def __str__(self):

    condiments = str(self.condiments)

    condiments = condiments[1:len(condiments)-1]

    info = '烤的时间:%s,烤的程度:%s,放的配料:%s'%(self.cookedLevel,self.cookedString,condiments)

    return info

    sp1 = SweetPotato()

    sp1.cook(1)

    print(sp1)

    print('=================================================================')

    sp1.cook(3)

    print(sp1)

    print('=================================================================')

    sp1.cook(3)

    sp1.addCondiments(['沙拉','蜜汁','黑椒'])

    print(sp1)

    print('=================================================================')

    sp1.cook(3)

    sp1.addCondiments(['芥末'])

    print(sp1)

    相关文章

      网友评论

          本文标题:烤地瓜

          本文链接:https://www.haomeiwen.com/subject/gsjbvxtx.html