Question: Write a Python code that creates a Vehicle class, a Motorcycle class that is a subclass of Vehicle with a wheels attribute set to 2,

Write a Python code that creates a Vehicle class, a Motorcycle class that is a subclass of Vehicle with a wheels attribute set to 2, and a Car class that is a subclass of Vehicle with a wheels attribute set to 4. Add a code that will raise an exception if the programmer tries to create a Vehicle.

I have this so far, but I don't know what to write to get something to print....

class Vehicle: def __init__(self): raise NotImplementedError ("You must use a subclass.")

class Motorcycle(Vehicle): def __init__(self): self.wheels = 2

class Car(Vehicle): def __init__(self): self.wheels = 4

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!