要求:
1、空调有品牌和价格两个属性,并且将属性私有化,提供公有的getXxx与setXxx方法对属性赋值和取值;
2、提供一个无返回值的无参数的开机的方法,内容打印一句话:“空调开机了...”;
3、提供一个无返回值的带1个int类型参数的定时关机的方法,(int类型的参数表示设定的分钟数),内容打印一句话:“空调将在xxx分钟后自动关闭...”;
4、在测试类中创建出空调对象,并给空调的品牌和价格赋任意值;
5、使用空调对象获取空调的品牌和价格并打印到控制台上;
6、使用空调对象调用开机方法;
7、使用空调对象调用定时关机方法,并传递具体数据值,在控制台上可以看到的效果为:空调将在xxx分钟后自动关闭... 其中语句中的“xxx”是调用方法时传递的具体数据值;
class kongtiao:
def getBrand(self):
print("空调品牌为",self.brand,"。")
def setBrand(self,brand):
self.brand = brand
def getPrice(self):
print("空调价格为",self.price,"元。")
def setPrice(self,price):
self.price = price
def open(self):
print("空调开机了...")
def close(self,num):
print("空调将在",num,"分钟后自动关机...")
k = kongtiao()
k.setBrand("海尔")
k.setPrice(3000)
k.getBrand()
k.getPrice()
k.open()
k.close(5)