Question: Please use Python, 2 (a) Write Python code that defines a Vehicle class of objects. Each object has an id number (integer) and a speed

Please use Python,

Please use Python, 2 (a) Write Python code that defines a Vehicle

2 (a) Write Python code that defines a Vehicle class of objects. Each object has an id number (integer) and a speed (integer in km/hr) attribute that are set up on creation. The class should have a --str - method that returns a string with the word Vehicle, its id and speed. (b) Define a Bus class that inherits from Vehicle and has a passengers attribute to hold the number of passengers. Override the --str-- method to include the string Bus (in place of Vehicle) and the number of passengers as well as the previous information (id, speed). (c) Also define a Truck class that inherits from Vehicle and has a load (tonnes) attribute. Again override the --str-- method to display this new information (including the string Truck instead of Vehicle or Bus). (d) Create two Vehicles (id 1 and 2, speed 30), two Buses (ids 3 and 4, speed 45, passengers 30 and 40), and two Trucks (id 5 and 6, speed 55, load 1 and 2). Put them into a list and print out all the members of the list and their attributes using the --str-- methods

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!