用python编写程序,实现将10位员工随机分配到3个办公室中,且最终的输出结果
时间: 2023-05-26 13:04:59 浏览: 62
具有格式化美观的效果。
```python
import random
employees = list(range(1, 11)) # 10位员工
offices = [[] for _ in range(3)] # 3个办公室
# 随机分配员工
for employee in employees:
office = random.randint(0, 2)
offices[office].append(employee)
# 输出结果
for i, office in enumerate(offices):
print(f"办公室{i+1}的员工:")
for employee in office:
print(f"\t员工{employee}")
```
运行结果:
```
办公室1的员工:
员工5
员工8
员工9
办公室2的员工:
员工1
员工2
员工3
员工7
办公室3的员工:
员工4
员工6
员工10
```