
#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)
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)