用Python编写学生基本信息与成绩管理程序设计。主要功能是对学生基本信息、课程、课程成绩进行 管理。 (1)学生基本信息包括学号,班级,姓名。能按学号进行信息增加,删除,查询。 (2)课程信息包括课程号,课程名,课程学分。能按课程号进行信息增加,删除,查询。 (3)选课信息。包括学号,课程号,成绩。能够对成绩进行录入,修改,查询。 (4)成绩统计分析。 按课程计算课程平均分,及格率,输出某门课程成绩,绘制各课程平均成绩的统计图(柱状 图或者折线图);按学号输出学生各门课程成绩,统计学分。
时间: 2023-03-23 13:03:00 浏览: 75
python学生成绩管理系统
5星 · 资源好评率100%
以下是用 Python 编写学生基本信息和成绩管理程序的示例代码:
```python
class Student:
def __init__(self, student_id, name, grade):
self.student_id = student_id
self.name = name
self.grade = grade
class Course:
def __init__(self, course_id, name):
self.course_id = course_id
self.name = name
self.students = []
def add_student(self, student):
self.students.append(student)
def remove_student(self, student):
self.students.remove(student)
class Score:
def __init__(self, student, course, score):
self.student = student
self.course = course
self.score = score
class ScoreSystem:
def __init__(self):
self.students = []
self.courses = []
self.scores = []
def add_student(self, student):
self.students.append(student)
def remove_student(self, student):
self.students.remove(student)
def add_course(self, course):
self.courses.append(course)
def remove_course(self, course):
self.courses.remove(course)
def add_score(self, score):
self.scores.append(score)
def remove_score(self, score):
self.scores.remove(score)
def get_student_by_id(self, student_id):
for student in self.students:
if student.student_id == student_id:
return student
return None
def get_course_by_id(self, course_id):
for course in self.courses:
if course.course_id == course_id:
return course
return None
def get_score(self, student_id, course_id):
student = self.get_student_by_id(student_id)
course = self.get_course_by_id(course_id)
for score in self.scores:
if score.student == student and score.course == course:
return score
return None
def calculate_average_score(self, course_id):
course = self.get_course_by_id(course_id)
total_score = 0
count = 0
for score in self.scores:
if score.course == course:
total_score += score.score
count += 1
if count == 0:
return 0
else:
return total_score / count
def generate_course_report(self, course_id):
course = self.get_course_by_id(course_id)
report = f"{course.name}\n"
report += f"{'-' * 30}\n"
for student in course.students:
score = self.get_score(student.student_id, course.course_id)
if score:
report += f"{student.student_id}\t{student.name}\t{score.score}\n"
else:
report += f"{student.student_id}\t{student.name}\tN/A\n"
report += f"{'-' * 30}\n"
report += f"Average score: {self.calculate_average_score(course.course_id)}\n"
return report
def generate_student_report(self, student_id):
student = self.get_student_by_id(student_id)
report = f"{student.name}\n"
report += f"{'-' * 30}\n"
for course in self.courses:
score = self.get_score(student.student_id, course.course_id)
if score:
report += f"{course.course_id}\t{course.name}\t{score.score}\n"
else:
report += f"{course.course_id}\t{course.name}\tN/A\n"
report += f"{'-' * 30}\n"
阅读全文