#8位老师随机分配三个办公室 #方法1 import random teachers=['郭 靖','黄 蓉','林 玉','小龙女','石破天','令狐冲','钟 灵','阿 碧'] offices=[[],[],[]] for name in teachers: num=random.randint(0,2) offices[num].append(name) print(f"三个办公室的随机分配情况是;",offices) i=1 for office in offices: print(f"办公室{i}的人数是{len(office)},老师分别是: ",end='') for name in office: print(name.center(5),end='\t') i+=1 print() print('_'*100) #方法2 import random teachers=['郭 靖','黄 蓉','林 玉','小龙女','石破天','令狐冲','钟 灵','阿 碧'] office1=[] office2=[] office3=[] for name in teachers: index=random.randint(1,3) if index==1: office1.append((name)) elif index==2: office2.append(name) else: office3.append(name) offices=[office1,office2,o
#8位老师随机分配三个办公室
最新推荐文章于 2023-03-23 17:58:07 发布