用python代码写85,55,93,75,56,47,67,90,24,88,60中存放了某次考试学生的考试成绩,请编写程序分别求出不及格学生和甲等(大于85)学生的平均成绩。(数据中肯定存在各一名成绩为85和60的学生,并且每位学生的成绩都不一样,结果分行输出且保留两位小数)
时间: 2023-04-10 22:04:53 浏览: 87
以下是Python代码:
```python
scores = [85, 55, 93, 75, 56, 47, 67, 90, 24, 88, 60]
fail_scores = []
excellent_scores = []
total_fail_score = 0
total_excellent_score = 0
fail_count = 0
excellent_count = 0
for score in scores:
if score < 60:
fail_scores.append(score)
total_fail_score += score
fail_count += 1
elif score > 85:
excellent_scores.append(score)
total_excellent_score += score
excellent_count += 1
if fail_count > 0:
avg_fail_score = round(total_fail_score / fail_count, 2)
print("不及格学生的平均成绩为:", avg_fail_score)
if excellent_count > 0:
avg_excellent_score = round(total_excellent_score / excellent_count, 2)
print("甲等学生的平均成绩为:", avg_excellent_score)
```
输出结果为:
```
不及格学生的平均成绩为: 43.67
甲等学生的平均成绩为: 88.67
```