编写一个程序,根据某学校高三模拟考试部分学生总成绩,降序输出学生成绩 姓名,并输出最高分和最低分以及姓名
时间: 2024-02-25 18:56:38 浏览: 75
好的,以下是一个 Python 实现的示例代码:
```python
# 定义学生类
class Student:
def __init__(self, name, score):
self.name = name
self.score = score
# 学生列表
students = [
Student('张三', 85),
Student('李四', 92),
Student('王五', 78),
Student('赵六', 90),
Student('钱七', 88)
]
# 按成绩降序排序
students.sort(key=lambda x: x.score, reverse=True)
# 输出成绩、姓名和最高分、最低分
print('成绩 姓名')
for student in students:
print(f'{student.score} {student.name}')
print(f'最高分:{students[0].score} {students[0].name}')
print(f'最低分:{students[-1].score} {students[-1].name}')
```
输出结果如下:
```
成绩 姓名
92 李四
90 赵六
88 钱七
85 张三
78 王五
最高分:92 李四
最低分:78 王五
```
以上代码同样实现了一个简单的排序程序,并输出了学生的姓名。需要注意的是,如果有多个学生成绩相同,则输出任意一个学生的姓名即可。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231045021.png)
![-](https://img-home.csdnimg.cn/images/20241231044955.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![cpp](https://img-home.csdnimg.cn/images/20250102104920.png)
![c](https://img-home.csdnimg.cn/images/20250102104920.png)
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![class](https://img-home.csdnimg.cn/images/20250102104920.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![java](https://img-home.csdnimg.cn/images/20250102104920.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)