5. Initializing a class


What is wrong in my code?

class Car(object):
  def __init__(self, model, colour, mpg):
    self.model = model
    self.colour = colour
    self.mpg = mpg
model = "BMW 3 Series"
colour = "black"
mpg = 100
my_car = Car(model, colour, mpg)


what error message are you getting?

i would guess you spelled colour the British way while the exercise expects American grammar (color)


my_car does not have a color member variable.


well, problem solved then? I already suggested what you should do in that case


Yes, thanks. But I think it shouldn’t throw an error because of this spelling, which is also correct.


But the scale codecademy operates at, to include regex everywhere to allow for such small differences, is a lot of work. Go ahead with unittest sometimes when you have time, you will see how difficult the validation is, and how much work writing test cases is


Yes, I imagine it is dificult indeed.


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