class Car:# Initializting Attributes of Class Cardef__init__(self, color, brand, model):self.color = colorself.brand = brandself.model = modeldef repaint(self, new_color):self.color = new_color# Creating Object called "MyCar" along with attributesMyCar = Car("OrchidWhite", "Honda", "Amaze")# Extracting Information from the "My Car" Objectprint(f"My Car is a {MyCar.color}{MyCar.brand}{MyCar.model}")# My Car Repatined with Metallic BlueMyCar.repaint("MetallicBlue")# Extracting Information from the "My Car" Objectprint(f"After Repaint My Car is a {MyCar.color}{MyCar.brand}{MyCar.model}")
My Car is a OrchidWhite Honda Amaze
After Repaint My Car is a MetallicBlue Honda Amaze
Inheritance - Recap
Inheritance Implementation - Recap
Electric Car
class ElectricCar(Car):# Initializting Attributes of Class Eletric Cardef__init__(self, color, brand, model,battery_capacity=0):super().__init__(color,brand,model)self.battery_capacity = battery_capacitydef charge_battery(self, charge_amount):self.battery_capacity += charge_amount
Fuel Car
class FuelCar(Car):# Initializting Attributes of Class Fuel Cardef__init__(self, color, brand, model,TankSize=0):super().__init__(color,brand,model)self.TankSize = TankSizeself.fuel_level =0def RefuelTank(self, fuel_amount):ifself.fuel_level + fuel_amount >self.TankSize:print("Cannot refuel beyond tank capacity.")else:self.fuel_level += fuel_amount
Inheritance Implementation Output - Recap
Electric Car
PriyasCar = ElectricCar("Red", "Tesla", "Model 3", battery_capacity=75)# Extracting Information from the "Priyas Car" Objectprint(f"Priyas Car is a {PriyasCar.color}{PriyasCar.brand}{PriyasCar.model}")# My Car Repatined with Metallic Blue and Charged to 25%PriyasCar.repaint("MetallicBlue")PriyasCar.charge_battery(25)# Extracting Information from the "Priyas Car" Objectprint(f"After Repaint Priyas Car is a {PriyasCar.color}{PriyasCar.brand}{PriyasCar.model}. Having Current Capacity {PriyasCar.battery_capacity}")
Priyas Car is a Red Tesla Model 3
After Repaint Priyas Car is a MetallicBlue Tesla Model 3. Having Current Capacity 100
Fuel Car
MyCar = FuelCar("OrchidWhite", "Honda", "Amaze", TankSize=40)# Extracting Information from the "My Car" Objectprint(f"My Car is a {MyCar.color}{MyCar.brand}{MyCar.model} with TankSize {MyCar.TankSize} Ltrs")MyCar.RefuelTank(30)print(f"My Car is a {MyCar.color}{MyCar.brand}{MyCar.model} with TankSize {MyCar.TankSize} Ltrs. \n Current Fuel Level is {MyCar.fuel_level} ")
My Car is a OrchidWhite Honda Amaze with TankSize 40 Ltrs
My Car is a OrchidWhite Honda Amaze with TankSize 40 Ltrs.
Current Fuel Level is 30
Episode 17
Multiple Inheritance
Multiple Inheritance
Multiple Inheritance - Implementation
Basic Smart System
class SmartFeatures():# Initializting Attributes of Smart Featuresdef__init__(self, autopilot=False, parking_assist=False, lane_keep_assist=False):self.autopilot = autopilotself.parking_assist = parking_assistself.lane_keep_assist = lane_keep_assist
Smart Electric Car
class SmartElectricCar(ElectricCar, SmartFeatures):# Initializting Attributes of Class Eletric Cardef__init__(self, color, brand, model,battery_capacity=0,autopilot=False, parking_assist=False, lane_keep_assist=False): ElectricCar.__init__(self,color,brand,model,battery_capacity) SmartFeatures.__init__(self,autopilot, parking_assist, lane_keep_assist)def describe_car(self):print(f"Car is a {self.color}{self.brand}{self.model}. Having Current Capacity {self.battery_capacity}")ifself.autopilot ==True:print(f"Car has Auto Pilot System too!!!!")
Smart Fuel Car
class SmartFuelCar(FuelCar, SmartFeatures):# Initializting Attributes of Class Fuel Cardef__init__(self, color, brand, model,TankSize=0,autopilot=False, parking_assist=False, lane_keep_assist=False): FuelCar.__init__(self,color,brand,model,TankSize) SmartFeatures.__init__(self,autopilot, parking_assist, lane_keep_assist)def describe_car(self):print(f"My Car is a {self.color}{self.brand}{self.model} with TankSize {self.TankSize} Ltrs. \n Current Fuel Level is {self.fuel_level} ")ifself.autopilot ==True:print(f"Car has Auto Pilot System too!!!!")
Multiple Inheritance verification
Multiple Inheritance Output
Electric Car
PriyasCar = SmartElectricCar("Red", "Tesla", "Model 3", battery_capacity=75,autopilot=True, parking_assist=True,lane_keep_assist=False)# Extracting Information from the "Priyas Car" ObjectPriyasCar.describe_car()# My Car Repatined with Metallic Blue and Charged to 25%PriyasCar.repaint("MetallicBlue")PriyasCar.charge_battery(25)# Extracting Information from the "Priyas Car" ObjectPriyasCar.describe_car()
Car is a Red Tesla Model 3. Having Current Capacity 75
Car has Auto Pilot System too!!!!
Car is a MetallicBlue Tesla Model 3. Having Current Capacity 100
Car has Auto Pilot System too!!!!
Fuel Car
MyCar = SmartFuelCar("OrchidWhite", "Honda", "Amaze", TankSize=40, autopilot=False, parking_assist=True, lane_keep_assist=False)# Extracting Information from the "My Car" ObjectMyCar.describe_car()MyCar.RefuelTank(30)MyCar.describe_car()
My Car is a OrchidWhite Honda Amaze with TankSize 40 Ltrs.
Current Fuel Level is 0
My Car is a OrchidWhite Honda Amaze with TankSize 40 Ltrs.
Current Fuel Level is 30