|
|
发表于 2020-8-3 12:25:54
|
显示全部楼层
要继承自 Car 类
- from car import Car
- class ElectricCar(Car):
- def __init__(self, brand, size):
- super().__init__(brand, size)
- self.battery = 100
- self.rm = 100
- def battery(self):
- print('The electric capacity of electric vehicles is: ' + self.battery)
- def rm(self):
- print('The estimated remaining mileage of electric vehicle is: ' + self.rm)
- def running(self, C):
- C = int(C)
- self.miles += C
- self.rm -= C
- self.battery -= (0.1) * C
- my_new_car = ElectricCar('Tesla', 'Model S')
- my_new_car.running(55)
- my_new_car.rm()
- my_new_car.battery()
复制代码 |
|