设计自定义机动车类
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()
全部评论
相关推荐
点赞 评论 收藏
分享
01-23 14:54
同济大学 Java 点赞 评论 收藏
分享

点赞 评论 收藏
分享