基于Python的成绩管理系统
时间: 2023-11-19 14:49:07 浏览: 129
基于python的学生成绩管理系统
基于Python的成绩管理系统是一个用于管理学生信息和成绩的系统。该系统可以实现以下功能:
1. 添加学生信息和成绩
2. 修改学生信息和成绩
3. 删除学生信息和成绩
4. 查询学生信息和成绩
5. 统计学生的平均成绩和绩点
系统的实现可以借助Python的面向对象编程思想,将学生和成绩作为对象,通过定义类和方法来实现各个功能。
以下是一个示例代码,展示了如何通过Python实现一个简单的基于命令行界面的成绩管理系统:
```python
class Student:
def __init__(self, student_id, name, c_score, python_score, java_score):
self.student_id = student_id
self.name = name
self.c_score = c_score
self.python_score = python_score
self.java_score = java_score
def calculate_gpa(self):
total_score = self.c_score + self.python_score + self.java_score
gpa = (total_score - 180) / 30
return round(gpa, 2)
class GradeManagementSystem:
def __init__(self):
self.students = []
def add_student(self, student):
self.students.append(student)
def remove_student(self, student_id):
for student in self.students:
if student.student_id == student_id:
self.students.remove(student)
break
def update_student(self, student_id, updated_student):
for i, student in enumerate(self.students):
if student.student_id == student_id:
self.students[i] = updated_student
break
def get_student(self, student_id):
for student in self.students:
if student.student_id == student_id:
return student
def get_all_students(self):
return self.students
def print_student_info(self, student):
print("{:^6}\t{:^12}\t{:^8}\t{:^10}\t{:^10}\t{:^8}".format(
'ID', '姓名', 'C语言成绩', 'Python成绩', 'Java成绩', '绩点'))
print("{:^6}\t{:^12}\t{:^8}\t{:^8}\t{:^8}\t{:^8}".format(
student.student_id, student.name, student.c_score, student.python_score, student.java_score,
student.calculate_gpa()))
def print_all_students_info(self):
if len(self.students) == 0:
print('列表中无学生信息')
else:
for student in self.students:
self.print_student_info(student)
# 创建一个成绩管理系统的实例
system = GradeManagementSystem()
# 添加学生信息
student1 = Student('001', '张三', 80, 90, 85)
system.add_student(student1)
student2 = Student('002', '李四', 75, 85, 90)
system.add_student(student2)
# 打印所有学生信息
system.print_all_students_info()
```
阅读全文