8. modifying member variables still stuck on this class stuff?


#1



8. modifying member vatiables


Oops, try again. Make sure your Car class has a drive_car() method.

get this to work, move to the next problem

class Car(object):
    condition = "neww"
def __init__(self, model, color, mpg, drive_car):
    self.model = model
    self.color = color
    self.mpg   = mpg
def display_car(self):
    print "This is a %s %s with %s MPG." % (self.color, self.model,str(self.mpg))
    def drive_car(self, condition):
        self.condition=used
        
#my_car = Car("DeLorean", "silver", 88)

print my_car.condition

my_car.drive_car(Car)

print my_car.condition


#2

Be sure to indent your methods so they are inside the class definition.

drive_car will not be a parameter. Remove that one from the params list.


#3

Hi mtf,

thanks for your help, i did what you suggested and got the following error

Oops, try again. Make sure your Car class has a drive_car() method.
&
File "python", line 3
def init(self, model, color, mpg,):
^
IndentationError: unexpected indent

slowly, i am understanding this class stuff,

class Car(object):
    condition = "neww"  # i purposely mis-spelled 'new'
    def __init__(self, model, color, mpg,):
        self.model = model
        self.color = color
        self.mpg   = mpg
    def display_car(self):
        print "This is a %s %s with %s MPG." % (self.color, self.model, str(self.mpg))
    #def drive_car(self, condition):
        
        self.condition=used
        
my_car = Car("DeLorean", "silver", 88)

print my_car.condition

my_car.drive_car(self, condition)

print my_car.condition

thanks for your help mtf
jack


#9

Comments must match the indentation of the code in the block (or just remove it).

Be sure to write the value as a string...

self.condition = "used"

Aside

Give this page a read...


#10

gezzz, i didn't know comments #.... had to be indented also??

i'll ''' my code for the forum from now on'''

thanks

still not working??

i'll post in the forum, I think my problem has to do with how i've set
up the class structure, i don't know how to fix it however.

jack g


#11

here in is my code:

i think the problem is in the way I have set up the second set of parameters? still don't know how to fix it..

class Car(object):
    condition = "neww"
    def __init__(self, model, color, mpg,):
        self.model = model
        self.color = color
        self.mpg   = mpg
    def display_car(self):
        print "This is a %s %s with %s MPG." % (self.color, self.model, str(self.mpg))
    def drive_car(self, condition):
     
        self.condition ="used"
                  
        
        my_car = Car("DeLorean", "silver", 88)

print my_car.condition

my_car.drive_car(self, condition)

print my_car.condition

with this error
Oops, try again. Make sure your Car class has a drive_car() method.

mtf, aha, the ticks worked,, i'm learning slowly but Sheila , i gave up on shirly


#12

Remove the comma after mpg.

There should be no indentation on the instance declaration.

Remove the condition parameter.

This method takes no arguments.

my_car.drive_car()

Precede and follow code block sample with three back ticks...

```

# code here

```

#13

it's getting better:

code is

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

print "This is a %s %s with %s MPG." % (self.color, self.model,
str(self.mpg))

class my_car(object):
condition ="used"
def drive_car(self, condition):

self.condition ="used"

my_car = Car("DeLorean", "silver", 88)

print my_car.condition

my_car.drive_car()

print my_car.condition
'''

out 1 OOPS, TRY AGAIN. Make sure your Car class has a drive_car()
method. what does this mean/ please

output 2

This is a silver DeLorean with 88 MPG. ## this is new,, seems to be
working
new
Traceback (most recent call last):
File "python", line 21, in
AttributeError: 'Car' object has no attribute 'drive_car'

wont print the second print -print my_car.condition


#14

This should only have a self parameter. The method is not meant to take any arguments other than that.

Please give the page in this post a read for help with posting code samples...

https://discuss.codecademy.com/t/8-modifying-member-variables-still-stuck-on-this-class-stuff/82718/9


#15

thanks mtf

i used the ''' before and after'''

class Car(object):
    condition = "new"
    def __init__(self, model, color, mpg):
        self.model = model
        self.color = color
        self.mpg   = mpg  
        print "This is a %s %s with %s MPG." % (self.model, self.color,\
        str(self.mpg)) 
        
class my_car (object):
    condition ="used"
    def drive_car(self, condition):    
        self.condition ="used"  
        
my_car = Car("DeLorean", "silver", 88)
print my_car.condition
my_car.drive_car()
print my_car.condition

I don't know how to fix it, i'm a newbie, trying to learn, i am tired - i truly want to learn..i'll just wait for each piece of information to come down to help me fix this, however, ..........

i did reset the code re pasted it, still got errors???

Oops, try again. Make sure your Car class has a drive_car() method. this points to drive_car

This is a DeLorean silver with 88 MPG.
new

Traceback (most recent call last):
  File "python", line 17, in <module>
AttributeError: 'Car' object has no attribute 'drive_car'

thanks

jackg


#16

Those are not back ticks, but apostrophes. Look for the back tick on the same button as the tilde (~).

As long as your code is not properly formatted, this is going to be a difficult problem to solve. You're making us repeat ourselves continuously.

How many times has this been pointed out, already?


#17

mtf,

i'm sorry to have caused you and others to repeat stuff to me, i didn't
understand about the back tick, i do now,

from now on i'll use the back tick before and after to load my code
onto the forum,

thanks for letting me know about this.

jack g


#18

If you start a new topic, there is a template there already. Follow the questions and directions in the template, and paste your code in the section marked out for it. Replace the line, "Replace this line with your code" with your code. It will be formatted.

Since you may not be able to edit your last post, I will go back and format it for you and see if we cannot put this puppy to bed.


#19

mtf,

from the front of the codecademy there is this:

UNDER CONSTRUCTION

Hey there,

We are currently having a service outage, and some of our content is
unavailable. We are working hard to get this fixed, and appreciate your
patience!

Keep up the good work!

might this be causing a problem???


#20

That news to me. Looks like you may have to take a break.

That code is definitely a miss. We don't want a my_car class, just a Car class with properties and methods.

class Car(object):
    condition = "new"
    def __init__(self, ...):
        self. ...

    def description(self):
        print "This is a ..."

    def drive_car(self):
        self.condition = "used"

The ... means fill in your original data and content


#21

thanks mtf, i'm on it!


#22

hi mtf,

although my code isn't working, from your great help, i now understand this class structure, the code is very ordered, reads nicely,

class Car(object):  
    condition = "new"
    def __init__(self, model, color, mpg):
        self.model = model
        self.color = color
        self.mpg = mpg  
    def display_car(self):
        print "This is a %s %s with %s MPG." % (self.model, self.color,\
        str(self.mpg))   
    def drive_car(self):    
        self.condition ="used"
    def my_car(self):    
        my_car = Car("DeLorean", "silver", 88)   
print my_car.condition
my_car.drive_car()
print my_car.condition


this is cool, due to the back ticks, this prints or copies, exactly.  very nice, this should help you, 

> current error: 
> Oops, try again. Did you accidentally delete my_car?
> 

console error: 
Traceback (most recent call last):
  File "python", line 1, in <module>
  File "python", line 14, in Car
AttributeError: 'function' object has no attribute 'condition'

i checked the:
spelling-seems to be correct
all :, they seem to be where they are supposed to be
indents, seems to be where the're supposed to be
i don't see any stray commas
seems to me that all the periods are where they are supposed to be

i would appreciate some help..

thanks

jack g


#23

Seems you are not getting the hang of what an instance is. It is not a method of the class, but a stand alone object outside of the class definition.

my_car = Car("DeLorean", "silver", 88)

#24

hi mtf,

i guess not, what can i read to understand this?

can an instance in python be thought of as a one time occurrence?

thanks for the email

jack g


#25

One source can be this..

https://learnpythonthehardway.org/book/ex40.html