class Car:
def __init__(self,name,brand,max_people):
self.name=name
self.brand=brand
self.number_of_people=0
self.max_people=max_people
def show(self):
print(f'这是{self.brand}品牌的{self.name}汽车,限额{self.max_people}人,现在车上有{self.number_of_people}')
def run(self):
print(f'汽车{self.name}跑起来了')
def set_people(self,number_of_people):
if 0<=number_of_people<=self.max_people:
self.number_of_people=number_of_people
else:
print(f'这是{self.brand}品牌的{self.name}汽车,限额{self.max_people}人,您想加入{number_of_people}人,超过限额人数!!')
def increase_people(self):
if self.number_of_people<self.max_people:
self.number_of_people+=1
else:
print("已经满员了")
def reduce_people(self):
if self.number_of_people>0:
self.number_of_people-=1
else:
print("不能再减了")
byd=Car('仰望U8','BYD',8)
byd.set_people(7)
byd.reduce_people()
# byd.reduce_people()
# byd.reduce_people()
# byd.reduce_people()
# byd.reduce_people()
# byd.reduce_people()
# byd.reduce_people()
# byd.reduce_people()
bwm=Car('X5','BWM',5)
bwm.increase_people()
# bwm.increase_people()
# bwm.increase_people()
# bwm.increase_people()
# bwm.increase_people()
# bwm.increase_people()
bwm.set_people(8)
byd.show()
bwm.show()
byd.run()
bwm.run()
请到客户端“主题--自定义配置--valine”中填入ID和KEY