学生成绩管理系统编码实现
时间: 2023-10-29 10:04:46 浏览: 46
学生成绩管理系统主要包含学生信息管理和成绩管理两部分。下面我将简要地介绍一下如何实现一个简单的学生成绩管理系统。
1. 学生信息管理
学生信息管理主要包括添加学生、查询学生和删除学生三个功能。
添加学生功能:
```python
def add_student(students, student_id, name, gender, age):
student = {"id": student_id, "name": name, "gender": gender, "age": age}
students.append(student)
print("添加成功!")
```
查询学生功能:
```python
def search_student(students, student_id):
for student in students:
if student["id"] == student_id:
print("学号:", student["id"])
print("姓名:", student["name"])
print("性别:", student["gender"])
print("年龄:", student["age"])
return
print("未找到该学生!")
```
删除学生功能:
```python
def delete_student(students, student_id):
for student in students:
if student["id"] == student_id:
students.remove(student)
print("删除成功!")
return
print("未找到该学生!")
```
2. 成绩管理
成绩管理主要包括添加成绩、查询成绩和删除成绩三个功能。
添加成绩功能:
```python
def add_score(scores, student_id, course_name, score):
score = {"id": student_id, "course_name": course_name, "score": score}
scores.append(score)
print("添加成功!")
```
查询成绩功能:
```python
def search_score(scores, student_id):
for score in scores:
if score["id"] == student_id:
print("学号:", score["id"])
print("课程名:", score["course_name"])
print("成绩:", score["score"])
print("未找到该学生的成绩!")
```
删除成绩功能:
```python
def delete_score(scores, student_id, course_name):
for score in scores:
if score["id"] == student_id and score["course_name"] == course_name:
scores.remove(score)
print("删除成功!")
return
print("未找到该学生的成绩!")
```
上面的代码只是一个简单的示例,如果要实现一个完整的学生成绩管理系统,还需要添加一些其他功能,比如修改学生信息和成绩、统计学生平均成绩等。同时,还需要将数据持久化,可以使用文件、数据库等方式进行实现。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.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)