Solution Review 1: Cars and Engines!
This lesson provides and explains the solution to the challenge, 'Cars and Engines!'
We'll cover the following...
Solution #
Press + to interact
class Car:def __init__(self, model, color):self.model = modelself.color = colordef printDetails(self):print("Model:", self.model)print("Color:", self.color)class SedanEngine:def start(self):print("Car has started.")def stop(self):print("Car has stopped.")class Sedan(Car):def __init__(self, model, color):super().__init__(model, color)self.engine = SedanEngine()def setStart(self):self.engine.start()def setStop(self):self.engine.stop()car1 = Sedan("Toyota", "Grey")car1.setStart()car1.printDetails()car1.setStop()
Explanation
-
Line 2 – 4: Initialized car properties ...