设计自定义机动车类
class Vehicle:
def __init__(self, vehicle_type, vehicle_no):
self.vehicle_type = vehicle_type
self.vehicle_no = vehicle_no
def start(self):
print(f"您乘坐的是{self.vehicle_type},{self.vehicle_no}已启动")
def stop(self):
print(f"您乘坐的是{self.vehicle_type},{self.vehicle_no}已停止")
class Taxi(Vehicle):
def __init__(self, vehicle_type, vehicle_no, company):
super().__init__(vehicle_type, vehicle_no)
self.company = company
def start(self):
print(f"乘客您好!\n我是{self.company}的,我的车牌号:{self.vehicle_no}, 请问您要去哪里?")
def stop(self):
print(f"目的地到了,请您付款下车,感谢您乘坐{self.vehicle_type},欢迎下次乘坐~")
class Car(Vehicle):
def __init__(self, vehicle_type, vehicle_no, owner):
super().__init__(vehicle_type, vehicle_no)
self.owner = owner
def start(self):
print(f"我是{self.owner},我的{self.vehicle_type}真好看!")
def stop(self):
print("目的地到啦,我们去玩儿吧!")
class Bus(Vehicle):
def __init__(self, vehicle_type, vehicle_no, stations):
super().__init__(vehicle_type, vehicle_no)
self.stations = stations
def start(self):
print(f"我是{self.vehicle_type},上有天堂下游苏杭~")
def stop(self):
print(f"前方到站{self.stations}")
taxi = Taxi("杭州出租车", "浙A66666", "杭州xx集团")
car = Car("劳斯莱斯幻影", "浙A8888", "阿波波")
bus = Bus("杭州K155", "浙A15555", "立马回头")
taxi.start()
taxi.stop()
print("*"*50)
car.start()
car.stop()
print("*"*50)
bus.start()
bus.stop()
def __init__(self, vehicle_type, vehicle_no):
self.vehicle_type = vehicle_type
self.vehicle_no = vehicle_no
def start(self):
print(f"您乘坐的是{self.vehicle_type},{self.vehicle_no}已启动")
def stop(self):
print(f"您乘坐的是{self.vehicle_type},{self.vehicle_no}已停止")
class Taxi(Vehicle):
def __init__(self, vehicle_type, vehicle_no, company):
super().__init__(vehicle_type, vehicle_no)
self.company = company
def start(self):
print(f"乘客您好!\n我是{self.company}的,我的车牌号:{self.vehicle_no}, 请问您要去哪里?")
def stop(self):
print(f"目的地到了,请您付款下车,感谢您乘坐{self.vehicle_type},欢迎下次乘坐~")
class Car(Vehicle):
def __init__(self, vehicle_type, vehicle_no, owner):
super().__init__(vehicle_type, vehicle_no)
self.owner = owner
def start(self):
print(f"我是{self.owner},我的{self.vehicle_type}真好看!")
def stop(self):
print("目的地到啦,我们去玩儿吧!")
class Bus(Vehicle):
def __init__(self, vehicle_type, vehicle_no, stations):
super().__init__(vehicle_type, vehicle_no)
self.stations = stations
def start(self):
print(f"我是{self.vehicle_type},上有天堂下游苏杭~")
def stop(self):
print(f"前方到站{self.stations}")
taxi = Taxi("杭州出租车", "浙A66666", "杭州xx集团")
car = Car("劳斯莱斯幻影", "浙A8888", "阿波波")
bus = Bus("杭州K155", "浙A15555", "立马回头")
taxi.start()
taxi.stop()
print("*"*50)
car.start()
car.stop()
print("*"*50)
bus.start()
bus.stop()
全部评论
相关推荐
11-03 13:11
广东东软学院 游戏后端
后端转测开第一人:再怎么劝退也没用的 某些群体总以为在一个幸存者偏差的软件上看见了极少数秋招上岸某个大厂的个例就幻想上了 事实上自己打开ssob沟通1000+连个小厂面试都没 点赞 评论 收藏
分享
查看14道真题和解析