python的学生管理系统的代码
时间: 2023-12-08 22:38:38 浏览: 74
以下是一个简单的Python学生管理系统的代码,其中包括一个Student类和一些基本的操作函数:
```python
class Student:
stuID = ""
name = ""
sex = "M"
classID = "NULL"
# 设置学生ID
def setStuID(self, stuID):
self.stuID = stuID
# 设置学生姓名
def setName(self, name):
self.name = name
# 设置学生性别
def setSex(self, sex):
self.sex = sex
# 设置学生班级
def setClassID(self, classID):
self.classID = classID
# 获取学生ID
def getStuID(self):
return self.stuID
# 获取学生姓名
def getName(self):
return self.name
# 获取学生性别
def getSex(self):
return self.sex
# 获取学生班级
def getClassID(self):
return self.classID
# 添加学生信息
def addStudent(stuList, stuID, name, sex, classID):
stu = Student()
stu.setStuID(stuID)
stu.setName(name)
stu.setSex(sex)
stu.setClassID(classID)
stuList.append(stu)
# 删除学生信息
def delStudent(stuList, stuID):
for stu in stuList:
if stu.getStuID() == stuID:
stuList.remove(stu)
# 修改学生信息
def modifyStudent(stuList, stuID, name, sex, classID):
for stu in stuList:
if stu.getStuID() == stuID:
stu.setName(name)
stu.setSex(sex)
stu.setClassID(classID)
# 查询学生信息
def queryStudent(stuList, stuID):
for stu in stuList:
if stu.getStuID() == stuID:
print("学生ID:", stu.getStuID())
print("学生姓名:", stu.getName())
print("学生性别:", stu.getSex())
print("学生班级:", stu.getClassID())
# 显示所有学生信息
def showAllStudent(stuList):
for stu in stuList:
print("学生ID:", stu.getStuID())
print("学生姓名:", stu.getName())
print("学生性别:", stu.getSex())
print("学生班级:", stu.getClassID())
```
使用示例:
```python
# 创建一个学生列表
stuList = []
# 添加学生信息
addStudent(stuList, "001", "张三", "男", "一班")
addStudent(stuList, "002", "李四", "女", "二班")
addStudent(stuList, "003", "王五", "男", "三班")
# 显示所有学生信息
showAllStudent(stuList)
# 修改学生信息
modifyStudent(stuList, "001", "张三丰", "男", "一班")
# 显示修改后的学生信息
queryStudent(stuList, "001")
# 删除学生信息
delStudent(stuList, "002")
# 显示删除后的学生信息
showAllStudent(stuList)
```
阅读全文