Python 对象操作家具()

#coding = utf-8


class Home:
def __init__(self,new_area,new_info,new_addr):
self.area = new_area
self.info = new_info
self.addr = new_addr
self.left_area = new_area
self.contain_item = []

def __str__(self):
return "房子面积:%d,可用面积:%d,户型是:%s,地址是:%s,当前房间的物品有:%s"%(self.area,self.left_area,self.info,self.addr,str(self.contain_item))

def add_itime(self,item):
#self.left_area -= item.area
self.left_area -= item.get_area()
self.contain_item.append(item.name)


class Bed:
def __init__(self,new_name,new_area):
self.name = new_name
self.area = new_area

def __str__(self):
return "%s占用的面积是:%d"%(self.name,self.area)

def get_area(self):
return self.area

def get_name(self):
return self.name



fangzi = Home(129,"三室一厅","北京市 朝阳区 长安街 666号",)
print(fangzi)


bed1 = Bed("席梦思",4)
print(bed1)


fangzi.add_itime(bed1)
print(fangzi)


bed2 = Bed("三人床",6)
fangzi.add_itime(bed2)
print(fangzi)
阅读更多

没有更多推荐了,返回首页