|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
class Furniture:
def __init__(self,name,area):
self.name = name
self.area = area
def __str__(self):
return"%s占地%.2f"%(self.name,self.area)
class House:
def __init__(self,type,area):
self.type = type
self.area = area
self.remain = area
self.list = []
def __str__(self):
return("户型:%s\n总面积:%.2f[剩余:%.2f]\n家具:%s"
%(self.type,self.area,
self.remain,self.list))
def add(self,item):
print("要添加%s"%item.name)
if item.area>self.remain:
print("%s面积过大,无法添加。"%item.name)
return
self.list.append(item.name)
self.remain -= item.area
bed = Furniture("席梦思",4)
closet = Furniture("衣柜",2)
table = Furniture("餐桌",56)
myhouse = House("两室一厅",60)
myhouse.add(bed)
myhouse.add(closet)
myhouse.add(table)
print(bed)
print(closet)
print(table)
print(myhouse)
加粗那几行为什么没有else什么的直接就return了 它return什么了? |
|