10. Overriding Methods (Unexpected Indent Error)


#1



https://www.codecademy.com/en/courses/python-intermediate-en-egNXj/1/4?curriculum_id=4f89dab3d788890003000096#


it gives me the notorious unexpected indentation error: unexpected indent on line 23


it seems like all the other codes in other overriding methods threads. i dont see what is wrong with my code.


class Car(object):
    condition = "new"
    def __init__(self, model, color, mpg):
        self.model = model
        self.color = color
        self.mpg   = mpg
    def display_car(self):
        return "This is a %s %s with %s MPG."%(self.color,self.model,str(self.mpg))
    def drive_car(self):
        self.condition="used"

my_car = Car("DeLorean", "silver", 88)
print my_car.condition
my_car.drive_car()
print my_car.condition

class ElectricCar(Car):
    def __init__(self,model,color,mpg,battery_type):
        super(ElectricCar,self).__init__(model,color,mpg)
        self.battery_type=battery_type
my_car=ElectricCar("Ford","white",75,"molten salt")

    def drive_car(self):
        self.condition="like new"
print my_car.condition
my_car.drive_car()
print my_car.condition


#2

Just go upwards to the next line to see the current indentation level


#3

already did, they are aligned


#4

Yeah, they're not. That's what python is telling you, the indentation level increased unexpectedly. You're not looking at the first non-empty line immediately above 23


#5

I dont get it, why is 22 non-empty ? it looks quite empty to me. i deleted the spaces before def, used tab tried many times, it wont work.


#6

it's not non-empty. It's empty. Python ignores it. The line above it is the first non-empty one, so when looking upwards you'll have to skip all empty lines until you get to the first one that isn't empty


#7

Do you mean the problem is about indentation of line 21 ?


#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.