教室选手编号是[1,2,3,4,5,6,7,8,9,10],海选投票编号为[3,2,5,7,9,5,7,6,8,9,8,6,5.1,2,3,1,3,6,5],编写程序,统计各教师选手所得票数并输出
时间: 2023-09-29 17:08:24 浏览: 72
PCDMIS比武海选考试题.docx
以下是 Python 代码实现:
```python
# 定义教室选手编号和海选投票编号
classroom = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
votes = [3, 2, 5, 7, 9, 5, 7, 6, 8, 9, 8, 6, 5, 1, 2, 3, 1, 3, 6, 5]
# 初始化每个选手的得票数为0
vote_count = {num: 0 for num in classroom}
# 统计得票数
for num in votes:
if num in classroom:
vote_count[num] += 1
# 输出结果
for num, count in vote_count.items():
print(f"选手{num}得票数为{count}票")
```
输出结果为:
```
选手1得票数为2票
选手2得票数为2票
选手3得票数为3票
选手4得票数为0票
选手5得票数为4票
选手6得票数为3票
选手7得票数为2票
选手8得票数为2票
选手9得票数为2票
选手10得票数为0票
```
阅读全文