创建一个程序,用户输入一个班级的学生成绩,程序计算并输出平均分、最高分、最低分以及各分数段(优秀(90-100)、良好(80-89)、中等(70-79)、及格(60-69)、不及格(0-59))的学生人数。程序应允许用户连续输入多个学生的成绩,直到用户输入“end”为止
时间: 2024-12-08 22:19:11 浏览: 14
创建这样一个程序,首先需要设计一个循环结构来接收用户的输入,直到用户指定结束。我们可以使用Python语言来编写,因为它的简洁性和易读性非常适合这种交互式应用。以下是一个简单的伪代码描述:
```python
class Student:
def __init__(self, score):
self.score = score
def input_scores():
scores = []
while True:
score_str = input("请输入学生分数(输入'end'结束):")
if score_str.lower() == 'end':
break
try:
score = int(score_str)
scores.append(Student(score))
except ValueError:
print("无效输入,请输入数字。")
return scores
def analyze_scores(scores):
total_score = sum(student.score for student in scores)
avg_score = total_score / len(scores) if scores else None
max_score = max(score for score in scores)
min_score = min(score for score in scores)
result = {
"平均分": avg_score,
"最高分": max_score,
"最低分": min_score,
}
grades_distribution = {
"优秀": 0,
"良好": 0,
"中等": 0,
"及格": 0,
"不及格": 0,
}
for student in scores:
if 90 <= student.score < 100:
grades_distribution["优秀"] += 1
elif 80 <= student.score < 90:
grades_distribution["良好"] += 1
elif 70 <= student.score < 80:
grades_distribution["中等"] += 1
elif 60 <= student.score < 70:
grades_distribution["及格"] += 1
else:
grades_distribution["不及格"] += 1
result["分数分布"] = grades_distribution
return result
scores = input_scores()
result = analyze_scores(scores)
print(result)
阅读全文