求助大佬
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)))
大佬们,这个程序的错误在哪儿啊{:10_266:} {:10_266:} 第九行 不是逗号,小错误,你改下再试试 多出小错误
第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))) 还是不行,提示AttributeError: 'Ticket' object has no attribute 'calcPrice' sunrise085 发表于 2020-9-25 15:40
多出小错误
第9行,点写成逗号了
第13行,函数名大小写和下面调用的时候写的不一样
谢谢大佬
页:
[1]