Classes
Create a Vehicle Class
Learning objective: By the end of this lesson, students will have more practice creating classes in Python.
🎓 You Do
Define a class named Vehicle with the following members:
make: attribute for the vehicle’s make.model: attribute for the vehicle’s model.running: attribute for maintaining whether or not the vehicle is running. Initializeself.runningto a default ofFalsewithin the__init__()method instead of passing the value in as an argument.start(): method for changingrunningtoTrue. It should also print the string:"Starting up!"stop(): method for changingrunningtoFalse. It should also print the string:"Turning off."- Override the
__str__method so that it returns a string formatted as:The vehicle is a <make> <model>.<make>and<model>should be replaced with the actual values of the make and model of the vehicle.
Test out the class by instantiating it, creating a vehicle of your choice. Call the start() and stop() methods, and print some of its attributes:
car = Vehicle("Toyota", "RAV4")
print(car)
# prints: The vehicle is a Toyota RAV4.
print(car.running)
# prints: False
car.start()
# prints: Starting up!
print(car.running)
# prints: True