创建一个空调类,属性有品牌、价格、类型 三个属性,空调有制冷、制热、定时制冷、定时制热的方法,创建三个空调对象,为各个属性赋值 并且调用空调类中的各个方法
时间: 2023-04-08 19:02:33 浏览: 225
好的,这是一个关于编程的问题,我可以回答。以下是创建空调类的代码:
```
class AirConditioner:
def __init__(self, brand, price, type):
self.brand = brand
self.price = price
self.type = type
def cool(self):
print("制冷中...")
def heat(self):
print("制热中...")
def timed_cool(self, time):
print(f"定时制冷 {time} 分钟...")
def timed_heat(self, time):
print(f"定时制热 {time} 分钟...")
# 创建三个空调对象
ac1 = AirConditioner("格力", 2999, "挂壁式")
ac2 = AirConditioner("美的", 2599, "柜式")
ac3 = AirConditioner("海尔", 1999, "移动式")
# 为各个属性赋值
ac1.brand = "TCL"
ac1.price = 1999
ac1.type = "挂壁式"
ac2.brand = "格兰仕"
ac2.price = 2399
ac2.type = "柜式"
ac3.brand = "志高"
ac3.price = 1799
ac3.type = "移动式"
# 调用空调类中的各个方法
ac1.cool()
ac2.heat()
ac3.timed_cool(30)
ac1.timed_heat(60)
```
以上是创建空调类的代码,我希望能够帮到你。