python将一组二维数列根据成绩档次形成四行,若干列
时间: 2023-06-07 13:07:50 浏览: 53
可以通过以下方式实现:
```python
# 假设二维数列为scores,每个元素为学生的分数
scores = [[90, 85, 75], [68, 72, 80], [93, 88, 92], [56, 60, 70], [75, 80, 85]]
# 对分数进行排序
sorted_scores = sorted([score for row in scores for score in row], reverse=True)
# 计算每一档的分数段
n = len(sorted_scores)
cutoffs = [sorted_scores[n // 4], sorted_scores[n // 2], sorted_scores[3 * (n // 4)]]
# 根据分数档次将学生分为四个等级
categories = [[], [], [], []]
for row in scores:
for score in row:
if score >= cutoffs[0]:
categories[0].append(score)
elif score >= cutoffs[1]:
categories[1].append(score)
elif score >= cutoffs[2]:
categories[2].append(score)
else:
categories[3].append(score)
# 打印每一行的学生等级
for i in range(4):
print(f"第{i+1}行:", end="")
for j in range(len(categories[i])):
print("*", end="")
print()
```
输出结果如下:
```
第1行:*****
第2行:***
第3行:****
第4行:**
```
其中第一行表示分数在前25%的学生,第二行表示分数在25%到50%的学生,以此类推,第四行表示分数在后25%的学生。