Initializing a class


#1

https://www.codecademy.com/courses/learn-python/lessons/classes/exercises/initializing-a-class?action=lesson_resume

###error messages.

File “python”, line 3
def init(self, model, color, mpg):
^
IndentationError: unindent does not match any outer indentation level

–> Please suggest what went wrong in below codes :


class Car(object):
	condition="new"
  def __init__(self, model, color, mpg):
    self.model = model
    self.color = color
		self.mpg = mpg
my_car = Car("DeLorean","silver",88)


#2

the indent level of these two lines:

	condition="new"
  def __init__(self, model, color, mpg):

do not match, the indent level should match


#3

ok, It worked, thank you !!

##correct codes:

class Car(object):
condition = "new"
def init(self, model, color, mpg):
self.model = model
self.color = color
self.mpg = mpg
my_car = Car(“DeLorean”,“silver”,88)


#4

Hi stetim94 ( Codecademy Moderator),

Here I’m pasting my code properly. But after replying spaces got changed.


#5

you need to use format to make indent show on the forum:

for multiply lines of code use code blocks (3 back-ticks above and below your code)


#6

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