list
#8个学生随机分配到3个教室的问题
import random
offices = [[], [], []]
names = ["a", "b", "c", "d", "e", "f", "g", "h"]
flag = 1
for i in names:
index = random.randint(0, 2)
offices[index].append(i)
for temp in offices:
print("教室%d有%d人:"%(flag,len(temp)))
for i in temp:
print(i,end="")
print()
print("*"*20)
flag +=1
教室1有3人:
aeh
********************
教室2有2人:
bg
********************
教室3有3人:
cdf
********************