1 输入一个班级的学生信息,并把学习成绩超过全班平均成绩的学生找出来,输出这部分学生的姓名和成绩。
时间: 2024-01-02 20:04:48 浏览: 67
好的,这是一个可以用 Python 编写的程序,下面是代码实现:
```python
class Student:
def __init__(self, name, score):
self.name = name
self.score = score
def main():
# 输入学生数量
n = int(input("请输入学生数量:"))
# 初始化学生列表
students = []
# 输入每个学生的信息
for i in range(n):
name = input("请输入第{}个学生的姓名:".format(i+1))
score = int(input("请输入第{}个学生的成绩:".format(i+1)))
students.append(Student(name, score))
# 计算平均成绩
total_score = 0
for student in students:
total_score += student.score
average_score = total_score / n
# 输出成绩超过平均成绩的学生信息
print("成绩超过平均成绩的学生信息如下:")
for student in students:
if student.score > average_score:
print("姓名:{},成绩:{}".format(student.name, student.score))
if __name__ == '__main__':
main()
```
程序中定义了一个 `Student` 类表示学生,包含 `name` 和 `score` 两个属性;然后输入学生数量和每个学生的信息;接着计算平均成绩,并输出成绩超过平均成绩的学生信息。
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)