现在有8位老师,3个办公室,要求将8位老师随机的分配到三个办公室中
import random
teachers = ['aa', 'bb', 'cc', 'dd', 'ee', 'ff', 'gg', 'hh']
offices = [[], [], []]
for name in teachers:
num = random.randint(0, 2)
offices[num].append(name)
i = 1
for office in offices:
print(f'办公室{i}的人数是{len(office)}.老师分别是:', end='')
i += 1
for name in office:
print(name, end='...')
print('')
# 输出:每次都不一样-可能会有的教室没有老师的情况
办公室1的人数是1.老师分别是:hh...
办公室1的人数是3.老师分别是:bb...ee...gg...
办公室1的人数是4.老师分别是:aa...cc...dd...ff...