Create a class Appliance and then define child classes WashingMachine, Refrigerator, Oven, each with unique features like power rating and a method to return their specific functionality.
Example 1:
Input: WashingMachine(500) Output: "This is a Washing Machine with 500W power rating."
Example 2:
Input: Oven(1000) Output: "This is an Oven with 1000W power rating."
Create a property for the power rating in each child class and a method to return a string describing the specific appliance and its power rating.
class Appliance:
def functionality(self):
pass
class WashingMachine(Appliance):
def __init__(self, power):
self.power = power
def functionality(self):
return f"This is a Washing Machine with {self.power}W power rating."
class Refrigerator(Appliance):
def __init__(self, power):
self.power = power
def functionality(self):
return f"This is a Refrigerator with {self.power}W power rating."
class Oven(Appliance):
def __init__(self, power):
self.power = power
def functionality(self):
return f"This is an Oven with {self.power}W power rating."
# Test the classes
wm = WashingMachine(500)
print(wm.functionality()) # Output: This is a Washing Machine with 500W power rating.
oven = Oven(1000)
print(oven.functionality()) # Output: This is an Oven with 1000W power rating.
Unlock AI & Data Science treasures. Log in!