I have been struggling to undo this error. I have already tried to change all the tabs into 4 spaces and I keep getting this indentation error. Did I miss something?
class Car:
def __init__(self):
def _init_(self, make, model, year):
self.make = make
self.model = model
self.year = year
def get_descriptive_name(self):
long_name = f'{self.year} {self.manufacturer} {self.mode}'
return long_name.title()
my_new_car = Car('audi', 'a4', '2019')
print(my_new_car.get_descriptive_name())
def _init_(self, make, model, year):
^
IndentationError: expected an indented block
CodePudding user response:
your problem is that you write def __init__()
Two times, and in the one of __init__
methods you forgot to write code or write pass. I recommend you to do this:
class Car:
def __init__(self, make, model, year):
self.make = make
self.model = model
self.year = year
def get_descriptive_name(self):
long_name = f'{self.year} {self.manufacturer} {self.mode}'
return long_name.title()
it is the most efficient way to do this.
CodePudding user response:
You have a unwanted __init__
function:
Remove this def __init__(self)
and it looks like:
class Car:
def __init__(self, make, model, year):
self.make = make
self.model = model
self.year = year
def get_descriptive_name(self):
long_name = f'{self.year} {self.manufacturer} {self.mode}'
return long_name.title()
my_new_car = Car('audi', 'a4', '2019')
print(my_new_car.get_descriptive_name())