用python写个学生管理系统
时间: 2023-10-31 20:06:40 浏览: 65
好的,以下是一个简单的学生管理系统的Python代码示例:
```python
class Student:
def __init__(self, name, id_num, grade):
self.name = name
self.id_num = id_num
self.grade = grade
class StudentManagementSystem:
def __init__(self):
self.students = []
def add_student(self, student):
self.students.append(student)
def remove_student(self, student):
self.students.remove(student)
def search_student(self, id_num):
for student in self.students:
if student.id_num == id_num:
return student
return None
def print_all_students(self):
for student in self.students:
print(f"Name: {student.name}, ID: {student.id_num}, Grade: {student.grade}")
# Example usage:
sms = StudentManagementSystem()
s1 = Student("Alice", "1234", "A")
sms.add_student(s1)
s2 = Student("Bob", "5678", "B")
sms.add_student(s2)
sms.print_all_students()
found_student = sms.search_student("1234")
if found_student:
print(f"Found student: {found_student.name}")
else:
print("Student not found.")
```
这个代码包括一个 `Student` 类,它有一个名称、ID号和成绩。 `StudentManagementSystem` 类是一个简单的管理系统,它可以添加、删除和查找学生,以及打印所有学生的信息。在这个示例中,我们创建了两个学生并将它们添加到管理系统中。我们还打印了所有学生的信息,并查找了一个学生。
阅读全文