python,类和对象练习

'''
按照一下要求定义一个游乐园门票类,并尝试计算2个成人+1个小孩子平日票价
1.平日票价100元
2.周末票价为平日票价120%
3.儿童半价

'''

class Ticket:
    pice = 100
    weekend = pice*1.2+pice
    def compute(self,adultcount,childcount,isweekend): 
        if(isweekend=='no'):
            total = int(adultcount)*self.pice+int(childcount)*(self.pice/2)
            print("应该支付总金额:",str(total))
        elif(isweekend=='yes'):
            total = int(adultcount)*self.weekend+int(childcount)*(self.weekend/2)
            print("应该支付总金额:",str(total))
        else:
            print("输入有误")


while True:
    print("welcome to 迪斯尼 ")
    adult = input("请输入成年人数量")
    child = input("请输入小孩数量")
    isweekend = input("是否是周末?yes/no")
    t = Ticket()
    t.compute(adult,child,isweekend)

 

转载于:https://www.cnblogs.com/pengpengzhang/p/8707933.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值