赞
踩
#8个老师随机放到3个办公室 import random #随机数生成 offices = [[],[],[]] #三个办公室 names = ['A','B','C','D','E','F','G','H'] #8个老师 for name in names: index = random.randint(0,2) #老师随机分配三个列表,索引为0,1,2 offices[index].append(name) #将老师名字加入列表中 i = 1 for office in offices: print("办公室%d的人数为:%d"%(i,len(office))) #输出办公室(1开始),所容纳人数 i += 1 for name in office: print("%s"%name,end='\t') print('\n') print("-"*10)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。