帮我用python语言写一个具有添加、删除、修改、查询学生信息及退出系统功能的简易学生管理系统
时间: 2023-08-10 11:04:59 浏览: 112
用python写的学生管理系统
好的,下面是一个简单的学生管理系统的Python代码:
```
# 定义学生类
class Student:
def __init__(self, name, age, gender, score):
self.name = name
self.age = age
self.gender = gender
self.score = score
# 定义管理系统类
class StudentManager:
def __init__(self):
self.students = []
# 添加学生信息
def add_student(self, student):
self.students.append(student)
print("添加成功!")
# 删除学生信息
def del_student(self, name):
for student in self.students:
if student.name == name:
self.students.remove(student)
print("删除成功!")
return
print("查无此人!")
# 修改学生信息
def modify_student(self, name, age, gender, score):
for student in self.students:
if student.name == name:
student.age = age
student.gender = gender
student.score = score
print("修改成功!")
return
print("查无此人!")
# 查询学生信息
def query_student(self, name):
for student in self.students:
if student.name == name:
print("姓名:", student.name)
print("年龄:", student.age)
print("性别:", student.gender)
print("分数:", student.score)
return
print("查无此人!")
# 运行管理系统
def run(self):
while True:
print("=" * 30)
print("学生管理系统")
print("1. 添加学生信息")
print("2. 删除学生信息")
print("3. 修改学生信息")
print("4. 查询学生信息")
print("5. 退出系统")
print("=" * 30)
choice = input("请输入您的选择:")
if choice == "1":
name = input("请输入学生姓名:")
age = input("请输入学生年龄:")
gender = input("请输入学生性别:")
score = input("请输入学生成绩:")
student = Student(name, age, gender, score)
self.add_student(student)
elif choice == "2":
name = input("请输入学生姓名:")
self.del_student(name)
elif choice == "3":
name = input("请输入学生姓名:")
age = input("请输入学生年龄:")
gender = input("请输入学生性别:")
score = input("请输入学生成绩:")
self.modify_student(name, age, gender, score)
elif choice == "4":
name = input("请输入学生姓名:")
self.query_student(name)
elif choice == "5":
print("感谢使用学生管理系统,再见!")
break
else:
print("输入有误,请重新输入!")
# 运行管理系统
if __name__ == "__main__":
manager = StudentManager()
manager.run()
```
运行后,程序将进入学生管理系统,根据提示进行操作即可。
阅读全文