学生管理系统python代码,
时间: 2024-01-01 14:23:05 浏览: 37
以下是一个简单的学生管理系统的Python代码示例:
```python
class Student:
def __init__(self, stuID, name, sex, classID):
self.stuID = stuID
self.name = name
self.sex = sex
self.classID = classID
student_infos = []
def add_student():
stuID = input("请输入学生ID:")
name = input("请输入学生姓名:")
sex = input("请输入学生性别:")
classID = input("请输入学生班级:")
student = Student(stuID, name, sex, classID)
student_infos.append(student)
print("学生信息添加成功!")
def delete_student():
stuID = input("请输入要删除的学生ID:")
for student in student_infos:
if student.stuID == stuID:
student_infos.remove(student)
print("学生信息删除成功!")
return
print("未找到该学生ID对应的学生信息!")
def modify_student():
stuID = input("请输入要修改的学生ID:")
for student in student_infos:
if student.stuID == stuID:
name = input("请输入修改后的学生姓名:")
sex = input("请输入修改后的学生性别:")
classID = input("请输入修改后的学生班级:")
student.name = name
student.sex = sex
student.classID = classID
print("学生信息修改成功!")
return
print("未找到该学生ID对应的学生信息!")
def get_all_students():
if len(student_infos) == 0:
print("暂无学生信息!")
else:
print("所有学生信息如下:")
for student in student_infos:
print("学生ID:", student.stuID)
print("学生姓名:", student.name)
print("学生性别:", student.sex)
print("学生班级:", student.classID)
print("-" * 20)
def main():
while True:
print_menu()
choice = input("请输入操作选项:")
if choice == "1":
add_student()
elif choice == "2":
delete_student()
elif choice == "3":
modify_student()
elif choice == "4":
get_all_students()
elif choice == "5":
print("退出系统!")
break
else:
print("无效的选项,请重新输入!")
if __name__ == "__main__":
main()
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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_column_c1.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)