1.Write a class named Car that has the following data attributes:
a) __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:
b)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. get_speed: The get_speed method should return the current speed
class Car:
def __init__(self, make, year_model):
self.__make = make
self.__year_model = year_model
self.__speed = 0
def accelerate(self):
self.__speed += 5;
def brake(self):
self.__speed -= 5;
def get_speed(self):
return self.__speed;
Comments
Leave a comment