|
发表于 2022-3-8 00:22:42
|
显示全部楼层
- class Ticket:
- def __init__(self,adult=2,child=1,weekend=False):
-
- self.adult=adult
- self.child=child
- self.money=100
- self.weekend=weekend
- def caladult(self):
- if self.weekend == True:
- self.moneyadult=(1.2)*self.money*self.adult
- else:
- self.moneyadult=self.money*self.adult
- def calchild(self):
- if self.weekend == True:
- self.moneychild=(0.6)*self.money*self.child
- else:
- self.moneychild=(self.money/2)*self.child
- def total(self):
- print("总共花销为:%s"%(self.moneychild+self.moneyadult))
复制代码
weekend要给属性 |
|