Error at 5/11


#1

Hey guys,

my code looks as follows (sorry, didnt know how to format it the right way, so i added "(tab)" where 4 spaces should be instead).

class Car(object):
(tab) condition = "new"
(tab) def init(self, model, color, mpg):
(tab)(tab) self.model = model
(tab)(tab) self.color = color
(tab)(tab) self.mpg = mpg

my_car = Car(model, color, mpg)
model = "DeLorean"
color = "silver"
mpg = 88

print my_car.condition

I get the following Error when clicking next, but codecademy still accepts it as correct and lets me proceed:

Traceback (most recent call last):
File "python", line 8, in
NameError: name 'model' is not defined

Can anyone of you help me? The concept of classes I think I understood. Problem for me at the moment is to understand the self argument and when to put self.something or (class_name).something and when not. If I try to follow the code one step at a time and try to understand it, I quite cant manage it. It seems like it functions differently from functions that i have learned before. Maybe one of you could give me some more insight in this too.

I appreciate all your efforts to help me improve and thank you in advance,
David


#2

This is your 8th line of code
my_car = Car(model, color, mpg)

my suggestion is you could try to put the value of the variable in to the argument when you created the variable my_car


#3
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) 
print my_car.model 
print my_car.color 
print my_car.mpg

Hello. I have an error, but where is it?

Traceback (most recent call last):
File "python", line 7, in
TypeError: object.new() takes no parameters


#4

Oh, I understood my error!


#5

what is the error?Kindly assist


#6

Here is how you format your post:
use the </> button and then copy and paste your code in :smile:
This will help other people find errors
:sweat_smile: I hope this helps ( I also hope this is what you were talking about when you talked about formatting)


#7
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) 
print my_car.model 
print my_car.color 
print my_car.mpg