class Room:
def init(self, no, dongwu):
self.no = no
self.dongwu = dongwu # 动物类对象
if name == 'main':
# 生成是个房间,将动物和房间绑定
rooms = [] # 保持十个房间
for i in range(1, 11):
if random.randint(0,1) == 1:
animal = Tiger(f'胖虎{i}')
else:
animal = Sheep(f'喜洋洋{i}')
r = Room(i, animal)
rooms.append(r)
for i in rooms:
print(i.no,i.dongwu.name)