Write a class named Car that has the following data attributes:
1) __year_model (for
the car’s year model); 2) __make (for the make of the car); 3)
__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 attributes. It should also assign 0 to the __speed
attribute.
The class should also have the following methods:
• accelerate: this method adds 5 to the __speed attribute each time
it is called
• brake: this method subtracts 5 from the __speed attribute each
time it is called
• get_speed: this method returns the current speed
Next, design a program that creates a Car object 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.
In Python code please
Write a class named Car that has the following data attributes: 1) __year_model (for the car’s year model); 2) __make (f
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Write a class named Car that has the following data attributes: 1) __year_model (for the car’s year model); 2) __make (f
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!