具体思路:
1 首先要先定义一个变量teacher_name存储八个老师的姓名
2 其次循环遍历老师姓名,并定义随机数字0-2,表示三个办公室。将这八个老师的名字随机分配到0-2中。
3 最后再通过for循环遍历打印出各个office的老师名字。
import random
teacher_name=['lisa','jiker','rose','plummer','Alice','Tom','QAozhi','SHla']
offices=[[],[],[]]
i=1
for name in teacher_name:
num = random.randint(0, 2)
offices[num].append(name)
for office in offices:
print(f'办公室{i}的人数为:{len(office)},老师名字为:')
for name in office:
print(name)
i += 1
标签:name,office,python,老师,---,offices,随机,teacher
From: https://blog.csdn.net/qq_48529664/article/details/139059377