Creating a class in Python
Question: I am working a program for school. We are to create a "class" and I keep
getting an attribute error but I can not figure out what I wrong can someone
please help. The directions are as followed. I have also included the code
that I have written in hopes someone can help me.

> Write a class named `Car` that has the following data attributes:
>
>   * `__year_model`( for the car’s year model)
>   * `__make`(for the car’s make of the car)
>   * `__speed`( for the car’s current speed)
>

>
> The Car class should have a `__init__` method that accepts the car’s year
> model and make as arguments. It should also assign `0` to the `__speed` data
> attribute.
>
> The class should also have the following methods:
>
>   * Accelerate: The `accelerate` method should add 5 to the speed data
> attribute each time it is called.
>   * Brake: The `brake` method should subtract 5 from the speed data
> attribute each time it is called.
>   * The `get_speed` method should return the current speed
>

>
> 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.
    
    
    class Car:
        def __init__(self, year_model, make, speed):
            self.year_model = year_model
            self.make = make
            self.speed = 0
    
        ############# year_model################
        def setYear_model(self, year_model):
            self.year_model = year_model
    
        def getYear_model(self):
            return self.year_model
    
        ############# Make################
        def setMake(self, make):
            self.make = make
    
        def getMake(self):
            return self.make
    
        ############# speed################
        def setSpeed(self, speed):
            if speed < 0:
                print("Speed cannot be negative")
            else:    
                self.speed = speed
    
        def getSpeed(self):
            return self.speed
    
        def accelerate(self, speed):
            self.speed += 5
            return self.speed
    
        def brake(self, speed):
            self.speed -= 5
            return self.speed 
    
        ############# str ############
        def __str__(self):
            return "Make : " + self.make + ", Model Year :" + \
                self.year_model + ", speed =" + str(self.speed)
    

my actual program

    
    
    import CarDefinition
    
    def main():
        my_car = CarDefinition.Car("2008", "Honda Accord")
    
        print(my_car)
    
        # Accelerate 5 times
        print ("Car is Accelerating: ")
        for i in range(5):
            my_car.accelerate()
            print ("Current speed: ", my_car.getSpeed())
    
        print()
        # Break 7 times
        print ("Car is braking: ")
        for i in range(7):
            my_car.brake()
            print ("Current speed: ", my_car.getSpeed())
    
        print("my_car values at prgram end:\n", my_car)
    
    
    
    
    
    main()    
    


Answer: Try something like this

    
    
    def accelerate(self):
     self.speed += 5
     return self.speed
    

