Untitled

mail@pastecode.io avatar
unknown
plain_text
20 days ago
870 B
0
Indexable
Never
class Car:
    def __init__(self, year, make, model,color):
        self.year = year
        self.make = make
        self.model = model
        self.color = color
    def get_descriptive_name(self):
        return f"{self.year} {self.make} {self.model} {self.color}"

class ElectricCar(Car):
    def __init__(self, year, make, model,color, battery_size):
        self.year = year
        self.make = make
        self.model = model
        self.color = color
        self.battery_size = battery_size
    def get_battery_size(self):
        return f"The battery size of the {self.get_descriptive_name()} is {self.battery_size} kWh."


car1 = Car(2021, "koenigsegg", "Jesko", "Black")
electric_car1 = ElectricCar(2022, "Tesla", "Model 3", "White",75)

print(car1.get_descriptive_name())
print(electric_car1.get_descriptive_name())
print(electric_car1.get_battery_size())
Leave a Comment