鱼C论坛

 找回密码
 立即注册
查看: 4029|回复: 2

对象没有属性为什么求解

[复制链接]
发表于 2018-4-22 15:02:47 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
class Car(object):
    def __init__(self,make,model,year):
        self.make=make
        self.model=model
        self.year=year
        self.odometer_reading=0

    def get_descriptive(self):
        long_naem=str(self.year)+' '+self.make+' '+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):
        if mileage>=self.odometer_reading:
            self.odometer_reading=mileage
        else:
            print"You can't roll back an odometer"

    def increment_odometer(self,miles):
        self.odometer_reading+=miles



class Battery(object):
    def __init__(self,battery_size=70):
        self.battery_size=battery_size

    def describe_battery(self):
        print"This car has a "+str(self.battery_size)+"-kwh battery"

    def get_range(self):
        if self.battery_size==70:
            ranges=240
        elif self.batter_size==85:
            ranges=270

        message='This car an go approximately '+str(ranges)
        message+=' miles on a full charge'
        print message

    def upgrade_battery(self):
        if self.battery_size != 85:
           self.battery_size==85
           


class ElectricCar(Car):
    def __inint__(self,make,model,year):
        super(ElectricCar,self).__init__(make,model,year)
        self.b=Battery()
        
a=ElectricCar('tesla','model s',2016)


a.b.describe_battery()
a.b.get_range()





Traceback (most recent call last):
  File "E:/Python27/python/9-9.py", line 57, in <module>
    a.b.describe_battery()
AttributeError: 'ElectricCar' object has no attribute 'b'
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2018-4-22 16:46:02 | 显示全部楼层
Car类第八行,ElectricCar类第二行都拼写错了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-4-22 20:06:32 | 显示全部楼层
chakyam 发表于 2018-4-22 16:46
Car类第八行,ElectricCar类第二行都拼写错了

没看清楚  谢谢了  已解决
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-12-29 15:09

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表