5. Initializing a class


#1

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)

#2

what error message are you getting?

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


#3

my_car does not have a color member variable.


#4

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


#5

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


#6

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


#7

Yes, I imagine it is dificult indeed.


#8

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