python学生信息管理系统源代码
时间: 2023-11-21 21:57:28 浏览: 93
以下是Python学生信息管理系统的源代码,包括student模块、StudentManagerSystem模块和main模块:
1. student模块
```python
class Student:
def __init__(self, id, name, age, gender, score):
self.id = id
self.name = name
self.age = age
self.gender = gender
self.score = score
def get_id(self):
return self.id
def get_name(self):
return self.name
def get_age(self):
return self.age
def get_gender(self):
return self.gender
def get_score(self):
return self.score
def set_name(self, name):
self.name = name
def set_age(self, age):
self.age = age
def set_gender(self, gender):
self.gender = gender
def set_score(self, score):
self.score = score
def __str__(self):
return f"{self.id}\t{self.name}\t{self.age}\t{self.gender}\t{self.score}"
```
2. StudentManagerSystem模块
```python
import os
import pickle
from student import Student
class StudentManagerSystem:
def __init__(self):
self.students = []
self.load_students()
def load_students(self):
if os.path.exists("students.pickle"):
with open("students.pickle", "rb") as f:
self.students = pickle.load(f)
def save_students(self):
with open("students.pickle", "wb") as f:
pickle.dump(self.students, f)
def show_menu(self):
print("===== 学生管理系统 =====")
print("1. 添加学生信息")
print("2. 删除学生信息")
print("3. 修改学生信息")
print("4. 查找学生信息")
print("5. 显示所有学生信息")
print("0. 退出系统")
def add_student(self):
id = input("请输入学生ID:")
name = input("请输入学生姓名:")
age = input("请输入学生年龄:")
gender = input("请输入学生性别:")
score = input("请输入学生成绩:")
student = Student(id, name, age, gender, score)
self.students.append(student)
print("添加成功!")
def remove_student(self):
id = input("请输入要删除的学生ID:")
for student in self.students:
if student.get_id() == id:
self.students.remove(student)
print("删除成功!")
return
print("未找到该学生!")
def modify_student(self):
id = input("请输入要修改的学生ID:")
for student in self.students:
if student.get_id() == id:
name = input("请输入学生姓名:")
age = input("请输入学生年龄:")
gender = input("请输入学生性别:")
score = input("请输入学生成绩:")
student.set_name(name)
student.set_age(age)
student.set_gender(gender)
student.set_score(score)
print("修改成功!")
return
print("未找到该学生!")
def search_student(self):
id = input("请输入要查找的学生ID:")
for student in self.students:
if student.get_id() == id:
print(student)
return
print("未找到该学生!")
def show_students(self):
for student in self.students:
print(student)
def run(self):
while True:
self.show_menu()
choice = input("请输入您的选择:")
if choice == "1":
self.add_student()
elif choice == "2":
self.remove_student()
elif choice == "3":
self.modify_student()
elif choice == "4":
self.search_student()
elif choice == "5":
self.show_students()
elif choice == "0":
self.save_students()
print("谢谢使用,再见!")
break
else:
print("输入有误,请重新输入!")
```
3. main模块
```python
from student_manager_system import StudentManagerSystem
if __name__ == "__main__":
sms = StudentManagerSystem()
sms.run()
```
阅读全文