设计一个学生成绩管理系统的大作业 要求有以下功能 输入基本信息 学号 姓名 课程 各科成绩等显示所有信息或根据要求输出信息 排序按学号性面貌门 课程分数 总分可以根据学生的能力自己扩充查询 按学号 姓名 某门课程的
时间: 2024-05-10 18:14:42 浏览: 89
成绩等查询功能,同时可以进行修改和删除操作。
以下是一个简单的学生成绩管理系统的实现示例:
1. 输入基本信息
定义一个学生类,包含学号、姓名、各科成绩和总分等属性:
```python
class Student:
def __init__(self, sid, name, scores):
self.sid = sid
self.name = name
self.scores = scores
self.total_score = sum(scores)
```
在主程序中,通过用户输入来创建学生对象并添加到学生列表中:
```python
students = []
while True:
sid = input("请输入学号(输入 q 结束):")
if sid == "q":
break
name = input("请输入姓名:")
scores = []
for subject in ["语文", "数学", "英语", "物理", "化学", "生物"]:
score = int(input("请输入{}成绩:".format(subject)))
scores.append(score)
student = Student(sid, name, scores)
students.append(student)
```
2. 显示所有信息或根据要求输出信息
定义一个函数来显示所有学生信息:
```python
def show_all_students(students):
print("{:<10}{:<10}{:<8}{:<8}{:<8}{:<8}{:<8}{:<8}".format("学号", "姓名", "语文", "数学", "英语", "物理", "化学", "生物"))
for student in students:
print("{:<10}{:<10}{:<8}{:<8}{:<8}{:<8}{:<8}{:<8}".format(student.sid, student.name, *student.scores))
```
定义函数来根据学号、姓名或课程分数进行排序:
```python
def sort_students(students, key):
if key == "学号":
students.sort(key=lambda student: student.sid)
elif key == "姓名":
students.sort(key=lambda student: student.name)
else:
subject_scores = []
for student in students:
subject_scores.append(student.scores["语文"])
subject_scores.append(student.scores["数学"])
subject_scores.append(student.scores["英语"])
subject_scores.append(student.scores["物理"])
subject_scores.append(student.scores["化学"])
subject_scores.append(student.scores["生物"])
if key == "总分":
students.sort(key=lambda student: student.total_score, reverse=True)
else:
students.sort(key=lambda student: student.scores[key], reverse=True)
```
定义函数来根据学号、姓名或课程分数进行查询:
```python
def search_students(students, key, value):
result = []
for student in students:
if key == "学号" and student.sid == value:
result.append(student)
elif key == "姓名" and student.name == value:
result.append(student)
elif key in ["语文", "数学", "英语", "物理", "化学", "生物"] and student.scores[key] == value:
result.append(student)
return result
```
3. 进行修改和删除操作
定义函数来修改学生成绩:
```python
def modify_student_scores(student):
print("修改学生成绩:")
for subject in ["语文", "数学", "英语", "物理", "化学", "生物"]:
score = int(input("请输入{}成绩:".format(subject)))
student.scores[subject] = score
student.total_score = sum(student.scores.values())
```
定义函数来删除学生信息:
```python
def delete_student(students, sid):
for i, student in enumerate(students):
if student.sid == sid:
students.pop(i)
print("删除成功!")
return
print("学号不存在!")
```
完整的程序代码如下:
阅读全文