i want the code for question a and b
1. Write Python code for the following: a) Car Class: 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: 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. 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. b) Write a definition for a class Device. The Device class has a data attribute for a type and a color. The class also has the following methods. • An __init_method for the class. The method should accept arguments for each of the data attributes. • An__str__method that returns a string showing the state of the object. Accessor and mutator methods for each data attribute.
1. Write Python code for the following: a) Car Class: Write a class named Car that has the following data attributes: _y
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
1. Write Python code for the following: a) Car Class: Write a class named Car that has the following data attributes: _y
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!