6. Referring to member variables


#1



https://www.codecademy.com/courses/python-intermediate-en-egNXj/0/6?curriculum_id=4f89dab3d788890003000096#


Oops, try again. It looks like you haven't created a Car object named my_car
Traceback (most recent call last):
File "python", line 15, in
NameError: name 'condition' is not defined


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

print my_car.model
print my_car.colour
print my_car.mpg


#2

class Car(object):
    def __init__(self, my_car):
        self.my_car = my_car
        
    def __init__(self, model, colour, mpg):
        self.model = model
        self.colour = colour
        self.mpg = mpg

There should be just one > init function

There are other errors too ...


#3

Hi, thanks but it still doesn't work even though I have put it in one.

def __init__(self, my_car, model, colour, mpg):
        self.my_car = my_car
        self.model = model
        self.colour = colour
        self.mpg = mpg

#4

Its creating the bug/error

model = "DeLorean"
colour = "silver"
mpg = 88
condition = "new"

here! you have to make an instance from class you created , I will stringly suggest to read the instruction again! if It does not make sense ,,,,do reply!!


#5

So sorry, but it says that my_car is not defined.

  model = "DeLorean"
    colour = "silver"
    mpg = 88
    condition = "new"
print condition(my_car)

print my_car.model
print my_car.colour
print my_car.mpg

#6

I will ask to check the sum that is just before 6th one...
Initializing a class


#7

Sorry, what do you mean?


#8

https://www.codecademy.com/en/courses/python-intermediate-en-egNXj/0/5?curriculum_id=4f89dab3d788890003000096

In this section we learnt to make an instance from a class!


#9

Sorry, but what am I meant do now? Sorry if I sound rude


#10

hehe, No its okay! :slight_smile:

Now you need to create an instance like If I had to create an instance of Car class
I'll do something like this...
if instance is X

X = Car("Model-z" , "red" , 90)

same way you have to create a my_car instance using Car class.


#11

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