10. Overriding Methods (Unexpected Indent Error)



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):

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

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

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


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


already did, they are aligned


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


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.


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


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


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