class Device:
    def __init__(self, name, power_watt):
        self.name = name
        self.power_watt = power_watt
        self.hours = 0 

    def set_hours(self, hours):
        self.hours = hours

    def energy_kwh(self):
        return (self.power_watt * self.hours) / 1000

class Home:
    def __init__(self):
        self.devices = []

    def add_device(self, device):
        self.devices.append(device)

    def total_energy(self):
        return sum(device.energy_kwh() for device in self.devices)

    def estimated_cost(self, price_per_kwh):
        return int(self.total_energy() * price_per_kwh)
        
tv = Device("TV", 200)
aircon = Device("에어컨", 2000)

tv.set_hours(5)
aircon.set_hours(2)

home = Home()
home.add_device(tv)
home.add_device(aircon)

price_per_kwh = 100

total_kwh = home.total_energy()
cost = home.estimated_cost(price_per_kwh)
print(f"총 사용 전력 {total_kwh}kWh. 예상 요금 {cost}원입니다.")

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: