赞
踩
from random import * # 引入随机库
employeeList = ['职员1', '职员2', '职员3', '职员4', '职员5', '职员6', '职员7', '职员8'] # 需要分配的职工名单列表
group = [[], [], []] # 定义三个列表存放分配信息
while True: # 因为有可能有的组没有分配到一个人,所以要使用循环来达成每一个组都有分配的人
for i in employeeList:
index = randint(0, 2)
group[index].append(i)
if len(group[0]) > 0 and len(group[1]) > 0 and len(group[2]) > 0:
break
else:
for i in group: # 这里需要把列表清空
i.clear()
print("第一组:{}\n第二组:{}\n第三组:{}".format(group[0], group[1], group[2]))
本人水平有限,欢迎各位大佬的批评指正。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。