为了账号安全,请及时绑定邮箱和手机立即绑定

Python,获取 AttributeError: 'ElectricCar' 对象没有属性

Python,获取 AttributeError: 'ElectricCar' 对象没有属性

撒科打诨 2021-06-09 18:33:16
class Car:    def __init__(self, year, make, model):        self.year = year        self.make = make        self.model = model        self.odometer_reading = 0    def get_descriptive_name(self):        long_name = str(self.year) + ' ' + str(self.make) + ' ' +str(self.model)        return long_name.title()    def read_odometer(self):        print('This car has ' + str(self.odometer_reading) + ' miles on it')    def update_odometer(self, mileage):        self.odometer_reading = mileage        if mileage >= self.odometer_reading:            self.odometer_reading = mileage        else:            print('you cant roll it back')class Battery():    """A simple attempt to model a battery for an electric car."""    def __init__(self, battery_size=70):        self.battery_size = battery_size    def describe_battery(self):        " ""Print a statement describing the battery size."""        print("This car has a " + str(self.battery_size) + "-kWh battery.")#The call to the battery attribute in the ElectricCar class is where the         #error emanatesclass ElectricCar(Car):    def __inti__(self, make, model, year):        super().__init__(make, model, year)        self.battery = Battery()my_telsa = ElectricCar('Volvo', 'models s', 2006)print(my_telsa.get_descriptive_name())my_telsa.battery.describe_battery()
查看完整描述

2 回答

?
子衿沉夜

TA贡献1828条经验 获得超3个赞

那么拼错错误,所以不是__inti__它__init__的ElectricCar课,所以是


那么:

...

class ElectricCar(Car):

    definit(self, make, model, year):

        super().__init__(make, model, year)

            self.battery = Battery()

    ...


查看完整回答
反对 回复 2021-06-22
?
噜噜哒

TA贡献1784条经验 获得超7个赞

_init_不在_inti_类 ElectricCar


查看完整回答
反对 回复 2021-06-22
  • 2 回答
  • 0 关注
  • 233 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信