学生信息管理系统源代码python
时间: 2024-05-25 14:09:00 浏览: 9
学生信息管理系统的源代码可能有很多版本和实现方式,这里我提供一种比较简单的实现方式,使用Python语言编写。
该学生信息管理系统主要包括以下功能:
1. 学生信息录入
2. 学生信息查询
3. 学生信息修改
4. 学生信息删除
以下是该系统的源代码(仅供参考):
```python
# 定义学生类
class Student:
def __init__(self, name, age, gender, id):
self.name = name
self.age = age
self.gender = gender
self.id = id
def __str__(self):
return '姓名:%s,年龄:%d,性别:%s,学号:%d' % (self.name, self.age, self.gender, self.id)
# 定义学生信息管理系统类
class StudentInfoManager:
def __init__(self):
self.students = []
# 添加学生信息
def add_student(self, student):
self.students.append(student)
print('添加成功!')
# 根据学号查询学生信息
def query_student(self, id):
for student in self.students:
if student.id == id:
print(student)
break
else:
print('未找到该学生!')
# 修改学生信息
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
print('修改成功!')
break
else:
print('未找到该学生!')
# 删除学生信息
def delete_student(self, id):
for student in self.students:
if student.id == id:
self.students.remove(student)
print('删除成功!')
break
else:
print('未找到该学生!')
# 测试代码
if __name__ == '__main__':
manager = StudentInfoManager()
# 添加学生信息
student1 = Student('张三', 18, '男', 1001)
manager.add_student(student1)
student2 = Student('李四', 20, '女', 1002)
manager.add_student(student2)
# 查询学生信息
manager.query_student(1001)
# 修改学生信息
manager.modify_student(1001, '王五', 19, '男')
manager.query_student(1001)
# 删除学生信息
manager.delete_student(1002)
```
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_lunwen.png)
![-](https://csdnimg.cn/download_wenku/file_type_lunwen.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)