Day_16课程回顾——11.13难受(OOP)

烤地瓜  代码

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)


存放家具:

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 1.1面向对象 面向对象(object-oriented ;简称: OO)至今还没有统一的概念 我这里把它定义为:...
    TENG书阅读 3,688评论 0 0
  • 定义__str__()方法 class Car: def __init__(self,newWheelNum,...
    曹操贼6阅读 3,017评论 0 0
  • class SweetPotato: def __init__(self,cookedLevel=0,cooke...
    我是大笨蛋阅读 1,814评论 0 0
  • 面向对象(Object Oriented Programming,OOP) ·1)解决菜鸟买电脑的故事 第一种方式...
    西多的大叔阅读 3,060评论 0 1
  • 恍恍惚惚过了20多年,还不知道自己想要活出怎样的人生。身在繁乱的闹市,仍有想有一片清净的内心,那里有黑与白的无声陈...
    我是哞哞哞哞羊阅读 1,387评论 0 0

友情链接更多精彩内容