Not sure solution is correct for python classes
<p>Here is the question;
create a car class with the following data attributes</p>

<pre><code>__year_model
__make
__speed
</code></pre>

<p>The class should have an <code>__init__</code> method that accepts the car's year model
and make as argument. The value should be assigned to the objects <code>__year_model</code> and <code>__make attributes</code>. It should assign 0 to the <code>__speed</code> data attribute</p>

<p>It should also have the following method:</p>

<p>accelerate: accelerate should add 5 to the speed data attribute each time it 
is called.</p>

<p>brake: this method should subtract 5 from the speed</p>

<p>get_speed: this should display the current speed</p>

<p>Next, design a program that creates a Car object, and then calls the accelerate method
five times. After each call to the accelerate method, get the current speed of the car and
display it. Then call the brake method five times. After each call to the brake method, get
the current speed of the car and display it.</p>

<pre><code>class Car:
    def __init__(self,year_model,make,speed):
        self.year_mode = year_model
        self.make = make
        self.speed = 0

    def accelerate(self,accelerate):
        self.accelerate = accelerate
        speed = 0
        for x in range(5):
            speed = speed + 5
            print speed

    def brake(self,brake):
        self.brake = brake
        speed = 0
        for x in range(5):
            brake = brake - 5
            print brake

    def get_speed(self):
        return self.speed


test = Car(2006,'Honda',100)
</code></pre>

<p>I know test is the instance. Is it also the object?
Thank you</p>

<p>Yes, <code>test</code> is an object, i.e. an instance of a class <em>is</em> an object.</p>

<p>Your class needs some work. According to the spec, <code>speed</code> is not supposed to be passed to <code>__init__()</code>. Remove that and initialise <code>self.__speed</code> to <code>0</code> in <code>__init__()</code>.</p>

<p><code>accelerate()</code> and <code>brake()</code> are not supposed to take arguments - each method should either increase the current speed by 5, or reduce the speed by 5. Therefore these methods do not require any arguments (other than <code>self</code>).</p>

<p>So <code>accelerate()</code> should be this:</p>

<pre><code>def accelerate(self):
    self.__speed += 5    # shorthand for self.speed = self.speed + 5
</code></pre>

<p>which simply increases the speed by 5 each time it is called. Note that <code>self</code> is used so that the member <code>__speed</code> is incremented, not some temporary local varible. You can do the same for <code>brake()</code>.</p>

<p>Other than that, add the tests that your assignment specifies: call <code>accelerate</code> 5 times printing the speed after each call. Similarly for the <code>brake</code> method. Does the output agree with what you would expect?</p>

<p>Test like this:</p>

<pre><code>car = Car(2006,'Honda')

for i in range(5):
    car.accelerate()
    print(car.get_speed())

for i in range(5):
    car.brake()
    print(car.get_speed())
</code></pre>

<p>Oh, and name your members as per the spec: <code>__speed</code>, not <code>speed</code> etc.</p>

python class object