当前位置:   article > 正文

Python 随机分配老师到办公室_import random import math offices = [[],[],[]] nam

import random import math offices = [[],[],[]] names = ['a','b','c','d','e',

3个办公室,8个老师,随机分配到3个办公室

import random

offices = [[], [], []]
names = ["A", "B", "C", "D", "E", "F", "G", "H"]

for name in names:
    index = random.randint(0, 2)
    offices[index].append(name)
i = 1
for office in offices:
    print("办公室%d的人数为:%d" % (i, len(office)))
    i += 1
    for name in offices:
        print("%s" % name, end="\t")
    print("\n")
    print("-"*20)


  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号