Sin descripción

electric_car.py 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. """A set of classes that can be used to represent electric cars."""
  2. from car import Car
  3. class Battery():
  4. """A simple attempt to model a battery for an electric car."""
  5. def __init__(self, battery_size=60):
  6. """Initialize the batteery's attributes."""
  7. self.battery_size = battery_size
  8. def describe_battery(self):
  9. """Print a statement describing the battery size."""
  10. print("This car has a " + str(self.battery_size) + "-kWh battery.")
  11. def get_range(self):
  12. """Print a statement about the range this battery provides."""
  13. if self.battery_size == 60:
  14. range = 140
  15. elif self.battery_size == 85:
  16. range = 185
  17. message = "This car can go approximately " + str(range)
  18. message += " miles on a full charge."
  19. print(message)
  20. class ElectricCar(Car):
  21. """Models aspects of a car, specific to electric vehicles."""
  22. def __init__(self, manufacturer, model, year):
  23. """
  24. Initialize attributes of the parent class.
  25. Then initialize attributes specific to an electric car.
  26. """
  27. super().__init__(manufacturer, model, year)
  28. self.battery = Battery()