|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- class Ticket:
- def __init__(self, weekend = False,child = False):
- self.price =100
- if weekend:
- self.increase = 1.2
- else:
- self.increase = 1
- if child:
- self,discount = 0.5
- else:
- self.discount = 1
- def calcprice(self , num):
- return self.price * self.increase * self.discount *num
- print("请输入成人与儿童的数量!")
- num1 = int(input("成人:"))
- num2 = int(input("儿童:"))
- if input("是否为休息日(YES/NO):").upper() == "YES":
- num3 = 1
- else:
- num3 = 0
- adult = Ticket(weekend = num3)
- child = Ticket(weekend = num3 , child = True)
- print("num1%d个大人 + num2%d个小孩平日票价为:%.2f" % (adult.calcPrice(num1) + child.calcPrice(num2)))
复制代码
大佬们,这个程序的错误在哪儿啊
多出小错误
第9行,点写成逗号了
第13行,函数名大小写和下面调用的时候写的不一样
第29行,格式化列表内参数以字符串中格式化字符个数不一样
- class Ticket:
- def __init__(self, weekend = False,child = False):
- self.price =100
- if weekend:
- self.increase = 1.2
- else:
- self.increase = 1
- if child:
- self.discount = 0.5
- else:
- self.discount = 1
- def calcPrice(self , num):
- return self.price * self.increase * self.discount *num
- print("请输入成人与儿童的数量!")
- num1 = int(input("成人:"))
- num2 = int(input("儿童:"))
- if input("是否为休息日(YES/NO):").upper() == "YES":
- num3 = 1
- else:
- num3 = 0
- adult = Ticket(weekend = num3)
- child = Ticket(weekend = num3 , child = True)
- print("%d个大人 + %d个小孩平日票价为:%.2f" % (num1,num2,adult.calcPrice(num1) + child.calcPrice(num2)))
复制代码
|
|