-
建立一个汽车类Auto,包括轮胎个数,汽车颜色,车身重量,速度等属性,并通过不同的构造方法创建实例。至少要求 汽车能够加速 减速 停车。 再定义一个小汽车类CarAuto 继承Auto 并添加空调、CD属性,并且重新实现方法覆盖加速、减速的方法
class Auto: def __init__(self, name, tyre_num, color='红', weight='1t', speed=100): self.name = name self.tyre_num = tyre_num self.color = color self.weight = weight self.speed = speed def speedup(self): self.speed += 20 print(f'加速{self.speed}') def speeddown(self): self.speed -= 20 print(f'减速{self.speed}') def brake(self): self.speed = 0 print(f'刹车{self.speed}') class CarAuto(Auto): def __init__(self, name, tyre_num='4', color='红', weight='1t', speed=100, air_condition='变频', CD='老式cd机'): super().__init__(name, tyre_num, color, weight, speed) self.speed = speed self.air_condition = air_condition self.CD = CD def speedup(self): self.speed += 20 print(f'加速{self.speed}') def speeddown(self): self.speed -= 20 print(f'减速{self.speed}') def brake(self): self.speed
day19作业
最新推荐文章于 2021-02-26 23:58:34 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)