### 正式严谨风 用Python编写学生成绩管理系统:具备多种信息操作与成绩查询功能
可以使用Python的面向对象编程思想,设计一个学生类,包含学生的姓名、学号、课程成绩等属性,然后再设计一个学生管理系统类,包含添加学生、删除学生、修改学生信息、查询学生信息、查询课程平均分、查询学生成绩等方法。
以下是一个简单的示例代码:
```python
class Student:
def __init__(self, name, id, scores):
self.name = name
self.id = id
self.scores = scores
class StudentManagementSystem:
def __init__(self):
self.students = []
def add_student(self, student):
self.students.append(student)
def delete_student(self, id):
for student in self.students:
if student.id == id:
self.students.remove(student)
return True
return False
def modify_student(self, id, name=None, scores=None):
for student in self.students:
if student.id == id:
if name:
student.name = name
if scores:
student.scores = scores
return True
return False
def search_student(self, id):
for student in self.students:
if student.id == id:
return student
return None
def search_course_average(self):
total_score = 0
total_count = 0
for student in self.students:
total_score += sum(student.scores)
total_count += len(student.scores)
return total_score / total_count
def search_student_score(self, id):
for student in self.students:
if student.id == id:
return student.scores
return None
```
使用示例:
```python
# 创建学生管理系统对象
sms = StudentManagementSystem()
# 添加学生
s1 = Student('张三', '001', [80, 90, 85])
sms.add_student(s1)
# 查询学生信息
s = sms.search_student('001')
print(s.name, s.id, s.scores)
# 修改学生信息
sms.modify_student('001', name='李四', scores=[85, 90, 95])
s = sms.search_student('001')
print(s.name, s.id, s.scores)
# 查询课程平均分
avg_score = sms.search_course_average()
print(avg_score)
# 查询学生成绩
scores = sms.search_student_score('001')
print(scores)
# 删除学生
sms.delete_student('001')
```
免责声明:
以上内容除特别注明外均来源于网友提问,创作工场回答,未经许可,严谨转载。