|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
number = {'Economy':9999, 'LuxuryCar':19999, 'SportCar':29999, 'SUV':39999}
class Cars:
def __init__(self, class_, brand, model, platenum, dayrent, loss, discount):
self.brand = brand
self.model = model
self.platenum = platenum
self.dayrent = dayrent
self.class_ = class_
if self.class_ == 'EconomyCar' or self.class_ == 'SUV':
self.discount = discount
else:
self.loss = loss
def count_price(self, days):
if self.class_ == 'EconomyCar':
self.count = (self.dayrent - self.discount) * days
elif self.class_ == 'LuxuryCar':
self.count = (self.dayrent + self.loss) * days
elif self.class_ == 'SportCar':
self.count = (self.dayrent + self.loss) * days
else:
if days <= 7:
count = (self.dayrent - self.discount) * days
else:
count = (self.dayrent - self.discount) * days * 0.7
return self.count
def get_carid(self):
self.carid = number[self.class_] + 1
number[self.class_] += 1
return self.carid
class Caroperation:
def __init__(self):
self.cars = {}
def register(self, class_):
self.brand = input("品牌:")
self.model = input("型号:")
self.platenum = input("车牌:")
self.dayrent = input("租金")
if class_ == 'EconomyCar' or class_ == 'SUV':
if class_ == 'EconomyCar':
self.discount = input("补贴:")
else:
self.discount = input("折扣:")
self.car = Cars(self.brand, self.model, self.platenum, self.dayrent, None, self.discount)
else:
if class_ == 'LuxuryCar':
self.loss = input("保险:")
else:
self.loss = input("损耗:")
self.car = Cars(self.brand, self.model, self.platenum, self.dayrent, self.loss, None)
self.cars[self.car.get_carid] = self.car
实验:main = Caroperation()
main.register('EconomyCar')
品牌:11
型号:11
车牌:11
租金11
补贴:11
[color=Red][color=Red]Traceback (most recent call last):
File "<pyshell#10>", line 1, in <module>
main.register('EconomyCar')
File "C:/Users/WL/OneDrive/桌面/12.py", line 45, in register
self.car = Cars(self.brand, self.model, self.platenum, self.dayrent, None, self.discount)
TypeError: Cars.__init__() missing 1 required positional argument: 'discount'
|
|