仿照武老师写的小游戏class game(): def __init__(self,name,age,sex,fight): self.name=name self.age=age self.sex=sex self.fight=fight def sky(self): self.fight=self.fight-100 def wate(self): self.fight=self.fight-200 def xiulian(self): self.fight=self.fight+150 def detai(self): print ("%s %d %s %d"%(self.name,self.age,self.sex,self.fight))t1=game('docker',20,'man',2000)t2=game('python',30,'woman',2500)t3=game('ansible',25,'shuige',3500)t1.detai()t1.wate()t1.sky()t1.sky()t1.xiulian()t1.detai()
来源:https://www.cnblogs.com/xincai2087/p/5306520.html