Advertisement
adolphuZ

Untitled

Jun 5th, 2024
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.85 KB | None | 0 0
  1. from abc import ABC, abstractmethod
  2. import copy
  3.  
  4. class Car(ABC):
  5.     @abstractmethod
  6.     def clone(self):
  7.         pass
  8.  
  9.     @abstractmethod
  10.     def specifications(self):
  11.         pass
  12.  
  13. class ElectricCar(Car):
  14.     def __init__(self, model, battery_capacity):
  15.         self.model = model
  16.         self.battery_capacity = battery_capacity
  17.  
  18.     def clone(self):
  19.         return copy.deepcopy(self)
  20.  
  21.     def specifications(self):
  22.         return f"ElectricCar(model={self.model}, battery_capacity={self.battery_capacity}kWh)"
  23.  
  24. class GasolineCar(Car):
  25.     def __init__(self, model, engine_capacity):
  26.         self.model = model
  27.         self.engine_capacity = engine_capacity
  28.  
  29.     def clone(self):
  30.         return copy.deepcopy(self)
  31.  
  32.     def specifications(self):
  33.         return f"GasolineCar(model={self.model}, engine_capacity={self.engine_capacity}L)"
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement