|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
大人 100
儿童半价
周六周日 票价*1.2
我是不是可以这样写?
为什么周末不会自动乘以1.2呢? 各位棒棒忙 谢谢
- class Ticket:
- price = 100
- chdPrice = price // 2
- def __init__(self,people,children):
- self.people = people
- self.cheldren = children
- def total(self):
- self.date = input('请输入星期几:(1-7)')
- if self.date == 6 or self.date == 7:
- return "门票金额共计:%.2f" % (int(self.people) * int(self.price) *1.2 + \
- int(self.cheldren) * int(self.chdPrice) * 1.2)
- else:
- return "门票金额共计:%.2f" % (int(self.people) * int(self.price) + int(self.cheldren) * int(self.chdPrice))
- p = input('请输入成人数量:')
- c = input('请输入儿童数量:')
- t = Ticket(p,c)
- print(t.total())
复制代码 |
|