(二)生成200个学生成绩数据,统计不及格、及格、中等、良好和优秀的占比
时间: 2024-06-13 16:08:02 浏览: 227
成绩统计,及格人数,不及格人数
4星 · 用户满意度95%
以下是生成200个学生成绩数据,统计不及格、及格、中等、良好和优秀的占比的Python代码:
```python
import random
grades = []
for i in range(200):
grades.append(random.randint(0, 100))
excellent = 0
good = 0
medium = 0
passing = 0
failing = 0
for grade in grades:
if grade >= 90:
excellent += 1
elif grade >= 80:
good += 1
elif grade >= 70:
medium += 1
elif grade >= 60:
passing += 1
else:
failing += 1
total = excellent + good + medium + passing + failing
print("优秀:{:.2%}".format(excellent / total))
print("良好:{:.2%}".format(good / total))
print("中等:{:.2%}".format(medium / total))
print("及格:{:.2%}".format(passing / total))
print("不及格:{:.2%}".format(failing / total))
```
阅读全文