用python编写一个学生管理系统
时间: 2023-07-18 13:19:05 浏览: 92
Python编写简单的学生管理系统
好的,下面是一个简单的学生管理系统的Python代码演示:
```python
class Student:
def __init__(self, name, age, gender, grade):
self.name = name
self.age = age
self.gender = gender
self.grade = grade
class StudentSystem:
def __init__(self):
self.students = []
def add_student(self):
name = input("请输入学生姓名:")
age = input("请输入学生年龄:")
gender = input("请输入学生性别:")
grade = input("请输入学生成绩:")
student = Student(name, age, gender, grade)
self.students.append(student)
print("添加成功!")
def search_student(self):
name = input("请输入要查找的学生姓名:")
for student in self.students:
if student.name == name:
print("姓名:{}\n年龄:{}\n性别:{}\n成绩:{}".format(student.name, student.age, student.gender, student.grade))
return
print("未找到该学生!")
def remove_student(self):
name = input("请输入要删除的学生姓名:")
for student in self.students:
if student.name == name:
self.students.remove(student)
print("删除成功!")
return
print("未找到该学生!")
def show_all_students(self):
for student in self.students:
print("姓名:{}\n年龄:{}\n性别:{}\n成绩:{}".format(student.name, student.age, student.gender, student.grade))
def run(self):
while True:
print("请选择操作:\n1.添加学生\n2.查找学生\n3.删除学生\n4.显示所有学生\n5.退出系统")
choice = input()
if choice == "1":
self.add_student()
elif choice == "2":
self.search_student()
elif choice == "3":
self.remove_student()
elif choice == "4":
self.show_all_students()
elif choice == "5":
print("谢谢使用!")
break
else:
print("输入有误,请重新输入!")
if __name__ == '__main__':
student_system = StudentSystem()
student_system.run()
```
这个学生管理系统包含了添加学生、查找学生、删除学生、显示所有学生等功能。你可以根据自己的需求对这个代码进行修改和完善。
阅读全文