Write a class named Car
that has the following data attributes:
__year_model
(for the car’s year model)__make
(for the make of the car)__speed
(for the car’s current speed)- The
Car
class should have an__init__
method that accepts the car’s year model and make as arguments. These values should be assigned to the object’s__year_model
and__make
data attributes. It should also assign 0 to the__speed
data attribute.
The class should also have the following methods: accelerate
Theaccelerate
method should add 5 to the speed data attribute each time it is called.brake
Thebrake
method should subtract 5 from the speed data attribute each time it is called.get_speed
Theget_speed
method should return the current speed.- Next, design a program that creates a
Car
object and then calls theaccelerate
method five times. After each call to theaccelerate
method, get the current speed of the car and display it. Then call thebrake
method five times. After each call to thebrake
method, get the current speed of the car and display it.