设计自定义机动车类

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()
全部评论

相关推荐

猫头夜鹰:图书管理系统能有面试就怪了,放十年前都不行
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-22 11:33
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务