7. 要求用户输入班级人数,之后依次输入每位学生的成绩,最后打印该班级总成绩和平均成绩
时间: 2024-09-22 20:05:40 浏览: 32
3.4 题目7 班级学生平均成绩_平均成绩_
为了实现这个功能,你可以采用编程语言如Python编写一段简单的程序。这里我将以Python为例来解释:
```python
class Student:
def __init__(self):
self.score = []
def input_scores():
class_size = int(input("请输入班级人数:"))
total_score = 0
for i in range(class_size):
score = float(input(f"请输入第{i+1}位同学的成绩:"))
total_score += score
student = Student()
student.score.append(score)
return total_score, student.score
total_score, scores = input_scores()
average_score = total_score / len(scores)
print(f"班级总成绩:{total_score}")
print(f"班级平均成绩:{average_score}")
# 如果需要,还可以计算最高分和最低分等
highest_score = max(scores)
lowest_score = min(scores)
print(f"最高分:{highest_score}")
print(f"最低分:{lowest_score}")
阅读全文