一个学校,有3个办公室,现在有8位老师等待工位的分配,请编写程序,完成随机的分配
import random
offices=[[],[],[]]
teachers=['1','2','3','4','5','6','7','8']
for teacher in teachers:
index=random.randint(0,2)
offices[index].append(teacher)
i=1
for office in offices:
num=len(office)
print('第%d个办公室有%d位老师'%(i,num))
print(office)
i+=1

博客围绕学校老师工位分配问题展开,有3个办公室和8位老师,需完成随机分配,借助Python编写程序可实现这一需求,体现了Python在解决实际问题中的应用。
6669

被折叠的 条评论
为什么被折叠?



