python编写学生管理系统
时间: 2023-06-29 18:06:04 浏览: 58
好的,我可以提供一个简单的学生管理系统代码示例,你可以参考一下:
```python
# 定义学生类
class Student:
def __init__(self, id, name, age, gender):
self.id = id
self.name = name
self.age = age
self.gender = gender
# 定义学生管理系统类
class StudentManager:
def __init__(self):
self.students = [] # 学生列表
# 添加学生信息
def add_student(self, student):
self.students.append(student)
print("添加成功!")
# 删除学生信息
def remove_student(self, student_id):
for student in self.students:
if student.id == student_id:
self.students.remove(student)
print("删除成功!")
return
print("该学生不存在!")
# 修改学生信息
def modify_student(self, student_id, name, age, gender):
for student in self.students:
if student.id == student_id:
student.name = name
student.age = age
student.gender = gender
print("修改成功!")
return
print("该学生不存在!")
# 查询学生信息
def query_student(self, student_id):
for student in self.students:
if student.id == student_id:
print("学生ID:", student.id)
print("姓名:", student.name)
print("年龄:", student.age)
print("性别:", student.gender)
return
print("该学生不存在!")
# 测试
if __name__ == '__main__':
manager = StudentManager()
s1 = Student(1001, "张三", 20, "男")
manager.add_student(s1)
manager.query_student(1001)
manager.modify_student(1001, "李四", 21, "女")
manager.query_student(1001)
manager.remove_student(1001)
manager.query_student(1001)
```
这个学生管理系统包含了一个学生类和一个学生管理系统类。学生类包含了学生的基本信息,学生管理系统类包含了添加、删除、修改和查询学生信息的方法。在测试部分,我们创建了一个学生管理系统对象,添加了一个学生信息,查询了该学生信息,修改了该学生信息,再次查询该学生信息,最后删除该学生信息并查询该学生信息。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![tar](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)