python学生信息管理系统
时间: 2023-09-18 16:14:39 浏览: 51
好的,下面是一个简单的Python学生信息管理系统的示例代码:
```python
class Student:
def __init__(self, name, age, gender):
self.name = name
self.age = age
self.gender = gender
class StudentManagementSystem:
students = []
@staticmethod
def add_student():
name = input("请输入学生姓名:")
age = input("请输入学生年龄:")
gender = input("请输入学生性别:")
student = Student(name, age, gender)
StudentManagementSystem.students.append(student)
print("添加成功!")
@staticmethod
def remove_student():
name = input("请输入要删除的学生姓名:")
index = -1
for i in range(len(StudentManagementSystem.students)):
if StudentManagementSystem.students[i].name == name:
index = i
break
if index != -1:
StudentManagementSystem.students.pop(index)
print("删除成功!")
else:
print("该学生不存在!")
@staticmethod
def search_student():
name = input("请输入要查询的学生姓名:")
index = -1
for i in range(len(StudentManagementSystem.students)):
if StudentManagementSystem.students[i].name == name:
index = i
break
if index != -1:
student = StudentManagementSystem.students[index]
print("姓名:{},年龄:{},性别:{}".format(student.name, student.age, student.gender))
else:
print("该学生不存在!")
@staticmethod
def show_students():
print("学生列表:")
for student in StudentManagementSystem.students:
print("姓名:{},年龄:{},性别:{}".format(student.name, student.age, student.gender))
@staticmethod
def show_menu():
print("欢迎使用学生信息管理系统!")
print("1. 添加学生")
print("2. 删除学生")
print("3. 查询学生")
print("4. 显示学生列表")
print("0. 退出系统")
@staticmethod
def run():
while True:
StudentManagementSystem.show_menu()
choice = input("请选择操作:")
if choice == "0":
print("谢谢使用!")
break
elif choice == "1":
StudentManagementSystem.add_student()
elif choice == "2":
StudentManagementSystem.remove_student()
elif choice == "3":
StudentManagementSystem.search_student()
elif choice == "4":
StudentManagementSystem.show_students()
else:
print("输入有误,请重新输入!")
if __name__ == '__main__':
StudentManagementSystem.run()
```
这个学生信息管理系统包含以下功能:
1. 添加学生
2. 删除学生
3. 查询学生
4. 显示学生列表
0. 退出系统
你可以根据自己的需求对其进行修改和扩展。
阅读全文