python学生学籍管理系统
时间: 2023-12-03 16:40:52 浏览: 87
以下是一个使用Python实现的学生学籍管理系统的示例代码,包括添加学生信息、查询学生信息、修改学生信息和删除学生信息等功能:
```python
# 定义学生类
class Student:
def __init__(self, name, age, gender, id):
self.name = name
self.age = age
self.gender = gender
self.id = id
# 定义学生管理系统类
class StudentManagementSystem:
def __init__(self):
self.students = []
# 添加学生信息
def add_student(self, student):
self.students.append(student)
# 查询学生信息
def query_student(self, id):
for student in self.students:
if student.id == id:
return student
return None
# 修改学生信息
def modify_student(self, id, name, age, gender):
for student in self.students:
if student.id == id:
student.name = name
student.age = age
student.gender = gender
return True
return False
# 删除学生信息
def delete_student(self, id):
for student in self.students:
if student.id == id:
self.students.remove(student)
return True
return False
# 测试代码
if __name__ == '__main__':
sms = StudentManagementSystem()
s1 = Student('Tom', 18, 'male', '001')
s2 = Student('Lucy', 19, 'female', '002')
sms.add_student(s1)
sms.add_student(s2)
print(sms.query_student('001').name) # 输出:Tom
sms.modify_student('001', 'Jerry', 20, 'male')
print(sms.query_student('001').name) # 输出:Jerry
sms.delete_student('001')
print(sms.query_student('001')) # 输出:None
```
阅读全文