Define three classes: Vehicle, Car and Truck. Vehicle will be the parent class of Car and Truck.

Randomly create five objects of Car and Truck using the for loop given below

The program should output the correct number of vehicles: Car and Truck objects.

The count of objects should be calculated within the class definitions.

Example output There are 5 Vehicle objects [‘Car’, ‘Car’, ‘Truck’, ‘Truck’, ‘Car’] 3 of them are Cars 2 of them are Trucks


# Define Vehicle class

# Define Car class

# Define Truck class

# Run the following lines of code

from random import choice

list_of_vehicles = [choice([‘Car’, ‘Truck’]) for x in range(5)]

for vehicle in list_of_vehicles:

if vehicle == ‘Car’:

# create an object of Car class

o = Car(‘Pick Car’)


# create an object of Truck class

c = Truck(‘Pick Truck’)

# print the list_of_vehicles

# print number of Vehicle objects

# print number of Car objects

# print number of Truck objects

"Looking for a Similar Assignment? Get Expert Help at an Amazing Discount!"
Looking for a Similar Assignment? Our Experts can help. Use the coupon code SAVE30 to get your first order at 30% off!

Hi there! Click one of our representatives below and we will get back to you as soon as possible.

Chat with us on WhatsApp