1 class Home: 2 def __init__(self,new_area,new_addr,new_price): 3 self.area = new_area 4 self.addr = new_addr 5 self.price = new_price 6 self.resarea = new_area 7 self.name = [] 8 9 def __str__(self): 10 dis = '房子在%s,大小是%d平米,单价是%d ,剩余面积是%d '%(self.addr, self.area, self.price, self.resarea) 11 dis+= '房子里家具有%s'%(str(self.name)) 12 return dis 13 def add_style(self,new_furn): 14 self.resarea -= new_furn.get_area() 15 self.name.append(new_furn.get_name()) 16 17 class Bed: 18 19 def __init__(self,bed_area,bed_name): 20 self.area = bed_area 21 self.name = bed_name 22 def __str__(self): 23 return '床的款式是%s,大小是%d'%(self.name, self.area) 24 def get_area(self): 25 return self.area 26 def get_name(self): 27 return self.name 28 29 fangzi = Home(100,'沈阳市',5000) 30 31 #print(fangzi) 32 33 bed1 = Bed(5,'双人床') 34 print(bed1) 35 36 fangzi.add_style(bed1) 37 print(fangzi) ~ "存放家具.py" 39L, 994C