I´m practicing creating objects and I’ve run into a snafu in relation to a syntax error that I don’t quite understand. VSCode tells me this:
AttributeError: type object 'Vehicle' has no attribute 'name'
Yet, I have created it. I am attempting to make the process of inheritance smoother by referencing each object to the class of Vehicle I’ve created, but Python doesn’t recognize this. What am I missing?
The code is below.
class Vehicle:
def __init__(self, name, max_speed, mileage, color):
self.name = name
self.max_speed = max_speed
self.mileage = mileage
self.color = color
Vehicle.color = "white"
print("The ", {Vehicle.name}, " is ", {Vehicle.color}, " running ", {Vehicle.max_speed}, " and with a mileage of ", {Vehicle.mileage})
class Bus(Vehicle):
pass
class Car(Vehicle):
pass
Bus("School Volvo", 180, 12)
Car("Audi Q5", 240, 18)
print(Bus(Vehicle))
print(Car(Vehicle))