Run ❯
Get your
own Python
server
❯
Run Code
Ctrl+Alt+R
Change Orientation
Ctrl+Alt+O
Change Theme
Ctrl+Alt+D
Go to Spaces
Ctrl+Alt+P
class Car: def __init__(self, brand, model): self.brand = brand self.model = model self.engine = self.Engine() class Engine: def __init__(self): self.status = "Off" def start(self): self.status = "Running" print("Engine started") def stop(self): self.status = "Off" print("Engine stopped") def drive(self): if self.engine.status == "Running": print(f"Driving the {self.brand} {self.model}") else: print("Start the engine first!") car = Car("Toyota", "Corolla") car.drive() car.engine.start() car.drive()
Start the engine first!
Engine started
Driving the Toyota Corolla