Answer to Question #195534 in Python for desmond

Question #195534

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


1
Expert's answer
2021-05-20T10:58:40-0400
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;

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS