一道Python复习题求解

编辑
3.编写一个汽车car类,类中用brand和country存储了汽车类的品牌名称和生产国家,类中有一个show_brand()函数可以打印出这个汽车的品牌名称。再编写一个电动车Bcar类,这个类继承汽车car类,且有自己的battery变量存储了电池的续航里程,且有自己的show battery()方法可以打印自己的续航里程数。之后,创建一个car类的对象,再创建一个E_car,类的对象。

这样?

img

class car:
    def __init__(self, brand,country):
        self.brand=brand
        self.country=country
    def show_brand(self):
        print(self.brand)
class Bcar(car):
    def __init__(self, brand, country,battery):
       super().__init__(brand, country)
       self.battery=battery
    def show_battery(self):
        print(self.battery)

car1=car('比亚迪','中国')
car1.show_brand()

bcar=Bcar('比亚迪电动','中国','500KM')
bcar.show_brand()
bcar.show_battery()

img


有帮助或启发麻烦点下【采纳该答案】,谢谢~~