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
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
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'
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.
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