Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env pytho
- """
- Herencia
- 9-9 Actualización de la batería:
- Agregue un método a la clase de la batería llamada upgrade_battery (). Este método
- debe verificar el tamaño de la batería y configurar la capacidad en 85 si aún no lo está.
- Haga un auto eléctrico con un tamaño de batería predeterminado,
- llame a get_range () una vez, y uego llame a get_range () por segunda vez después de actualizar la batería.
- Debieras ver un aumento en el rango del coche.
- """
- class Battery():
- """A simple attempt to model a battery for an electric car."""
- def __init__(self, battery_size=70):
- """Initialize the battery's attributes."""
- self.battery_size = battery_size
- def describe_battery(self):
- """Print a statement describing the battery size."""
- print("This car has a " + str(self.battery_size) + "-kWh battery.")
- def get_range(self):
- """Print a statement about the range this battery provides."""
- if self.battery_size == 70:
- range = 240
- elif self.battery_size == 85:
- range = 270
- message = "This car can go approximately " + str(range)
- message += " miles on a full charge."
- print(message)
- def upgrade_battery(self):
- """Este método debe verificar el tamaño de la batería y configurar la capacidad en 85 si aún no lo está."""
- print ("Old battery size = "+str (self.battery_size))
- self.battery_size=85
- print ("New battery size = " +str( self.battery_size ) +" upgrade !")
- class Car():
- """A simple attempt to represent a car."""
- def __init__(self, make, model, year):
- self.make = make
- self.model = model
- self.year = year
- self.odometer_reading = 0
- def get_descriptive_name(self):
- long_name = str(self.year) + ' ' + self.make + ' ' + self.model
- return long_name.title()
- def read_odometer(self):
- print("This car has " + str(self.odometer_reading) + " miles on it.")
- def update_odometer(self, mileage):
- if mileage >= self.odometer_reading:
- self.odometer_reading = mileage
- else:
- print("You can't roll back an odometer!")
- def increment_odometer(self, miles):
- self.odometer_reading += miles
- class ElectricCar(Car):
- """Represent aspects of a car, specific to electric vehicles."""
- def __init__(self, make, model, year):
- """Initialize attributes of the parent class. Then initialize attributes specific to an electric car."""
- super().__init__(make, model, year)
- self.battery = Battery()
- my_tesla = ElectricCar('tesla', 'model s', 2016)
- print(my_tesla.get_descriptive_name())
- my_tesla.battery.describe_battery()
- my_tesla.battery.get_range()
- my_tesla.battery.upgrade_battery()
- my_tesla.battery.get_range()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement