Modifying member variables


#1

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/learn-python/lessons/classes/exercises/modifying-member-variables?action=lesson_resume&link_content_target=interstitial_lesson

<In what way does your code behave incorrectly? Include ALL error messages.>
I need to print the car condition - should get "new"
than execute drive_car
and print the condition again - should get "used"
the instruction is to print the car condition. - how can I print the condition "new"
when I call print my_car.drive_car() I get “used”
<What do you expect to happen instead?>
when I print condition I should get "new"
call drive_car
print condition again I should get “used”

```python

class Car(object):
#condition = "new"
def init(self, model, color, mpg):
self.model = model
self.color = color
self.mpg = mpg
mpg = str(mpg)
def display_car(self):
return “This is a %s %s with %s MPG.” % (self.color, self.model, self.mpg)
def drive_car(self):
self.condition = "used"
return self.condition

my_car = Car(“DeLorean”, “silver”, 88)
print my_car.drive_car()

<do not remove the three backticks above>

#2

Please format your code correctly :grin:


#3

I managed thanks.
it’s working :grinning::grinning::grinning:


#4

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