用python写代码,小蓝给学生们组织了一场考试,卷面总分为100 分,每个学生的得分都是一个0 到100 的整数。请计算这次考试的最高分、最低分和平均分。 输入 输入的第一行包含一个整数n,表示考试人数。 接下来n 行,每行包含一个0 至100 的整数,表示一个学生的得分。 输出 输出三行。 第一行包含一个整数,表示最高分。 第二行包含一个整数,表示最低分。 第三行包含一个实数,四舍五入保留正好两位小数,表示平均分。
时间: 2024-03-27 09:38:32 浏览: 35
可以使用Python内置函数来实现这个问题。
代码实现如下:
```python
n = int(input())
scores = []
for i in range(n):
score = int(input())
scores.append(score)
max_score = max(scores)
min_score = min(scores)
avg_score = sum(scores) / n
print(max_score)
print(min_score)
print('{:.2f}'.format(avg_score))
```
相关问题
用Python写一个分析班级学生语文,数学,英语平均分和排名的代码
好的,下面是一个示例代码:
```
# 假设有一个包含学生信息的列表,其中每个学生都是一个字典,包含"name"(姓名),"chinese"(语文成绩),"math"(数学成绩)和"english"(英语成绩)键
students = [
{"name": "张三", "chinese": 85, "math": 90, "english": 60},
{"name": "李四", "chinese": 90, "math": 80, "english": 70},
{"name": "王五", "chinese": 60, "math": 60, "english": 80},
]
# 遍历每个学生,计算平均分和总分
for student in students:
name = student["name"]
chinese = student["chinese"]
math = student["math"]
english = student["english"]
total = chinese + math + english
average = total / 3
print(f"{name}的平均分是{average:.2f},总分是{total}")
# 根据总分排序
students.sort(key=lambda student: student["chinese"] + student["math"] + student["english"], reverse=True)
# 输出排名
for i, student in enumerate(students):
name = student["name"]
print(f"{name}的排名是{i + 1}")
```
输出结果如下:
```
张三的平均分是75.00,总分是235
李四的平均分是80.00,总分是240
王五的平均分是70.00,总分是200
李四的排名是1
张三的排名是2
王五的排名是3
```
用Python代码写一个学生管理系统
好的,以下是一个简单的学生管理系统的 Python 代码:
```python
class Student:
def __init__(self, name, id, grade):
self.name = name
self.id = id
self.grade = grade
class StudentManager:
def __init__(self):
self.students = []
def add_student(self, name, id, grade):
student = Student(name, id, grade)
self.students.append(student)
def remove_student(self, id):
for student in self.students:
if student.id == id:
self.students.remove(student)
return True
return False
def get_student(self, id):
for student in self.students:
if student.id == id:
return student
return None
def get_all_students(self):
return self.students
```
这个学生管理系统包含一个 `Student` 类和一个 `StudentManager` 类。`Student` 类用于表示一个学生,包含学生的姓名、学号和成绩。`StudentManager` 类用于管理学生,包含添加学生、删除学生、获取学生和获取所有学生等方法。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)