请编程实现统计以下考试成绩中优、良、中、及格、不及格的人数。其中100分制与五级等级制的对应关系为:90分及以上为优,80~89分为良,70~79分为中,60~69分为及格,60分以下为不及格。其中,使用函数设计的编程思想。
时间: 2024-05-19 14:16:15 浏览: 18
def count_grade(scores):
excellent = 0
good = 0
medium = 0
pass_ = 0
fail = 0
for score in scores:
if score >= 90:
excellent += 1
elif score >= 80:
good += 1
elif score >= 70:
medium += 1
elif score >= 60:
pass_ += 1
else:
fail += 1
return excellent, good, medium, pass_, fail
scores = [78, 89, 95, 67, 45, 80, 72, 55, 91]
excellent, good, medium, pass_, fail = count_grade(scores)
print("优秀:", excellent)
print("良好:", good)
print("中等:", medium)
print("及格:", pass_)
print("不及格:", fail)
相关问题
python请编程实现统计以下考试成绩中优、良、中、及格、不及格的人数。其中100分制与五级等级制的对应关系为:90分及以上为优,80~89分为良,70~79分为中,60~69分为及格,60分以下为不及格。其中,使用函数设计的编程思想。
def count_grade(score_list):
excellent = 0
good = 0
medium = 0
pass_grade = 0
fail = 0
for score in score_list:
if score >= 90:
excellent += 1
elif score >= 80:
good += 1
elif score >= 70:
medium += 1
elif score >= 60:
pass_grade += 1
else:
fail += 1
return excellent, good, medium, pass_grade, fail
score_list = [75, 88, 92, 60, 50, 81, 68, 95, 78, 63]
excellent, good, medium, pass_grade, fail = count_grade(score_list)
print("优:{}人\n良:{}人\n中:{}人\n及格:{}人\n不及格:{}人".format(excellent, good, medium, pass_grade, fail))
相关推荐
![asm](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![text/plain](https://img-home.csdnimg.cn/images/20210720083646.png)
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![whl](https://img-home.csdnimg.cn/images/20210720083646.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![whl](https://img-home.csdnimg.cn/images/20210720083646.png)