import random
# 1.定义三个容器保存三种球
whiteBalls = ['白','白','白','白']
redBalls = ['红','红','红']
blueBalls = ['蓝','蓝','蓝']
# 2.定义三个盒子 嵌套列表
boxes = [[],[],[]]
# 3.白球分配到三个盒子中
for box in boxes:
# 找到白球
# 添加白球
box.append(whiteBalls.pop(whiteBalls.index('白')))
# 4.三个容器合并,再进行分配
l = whiteBalls+redBalls+redBalls
whiteBalls.clear()
redBalls.clear()
blueBalls.clear()
for ball in l:
index = random.randint(0,2)
# 随机获取box
box = boxes[index]
# 添加球到盒子中
box.append(ball)