写基于python的学生管理系统设计开发的代码
时间: 2024-01-11 08:04:31 浏览: 78
好的,以下是一个简单的学生管理系统的Python代码:
```python
class Student:
def __init__(self, name, id_number, major):
self.name = name
self.id_number = id_number
self.major = major
class StudentManagementSystem:
def __init__(self):
self.students = []
def add_student(self, name, id_number, major):
student = Student(name, id_number, major)
self.students.append(student)
def remove_student(self, id_number):
for student in self.students:
if student.id_number == id_number:
self.students.remove(student)
def search_student(self, id_number):
for student in self.students:
if student.id_number == id_number:
return student
return None
def display_students(self):
for student in self.students:
print("Name: {}, ID Number: {}, Major: {}".format(student.name, student.id_number, student.major))
# Example usage
sms = StudentManagementSystem()
sms.add_student("John Smith", "1234", "Computer Science")
sms.add_student("Jane Doe", "5678", "Mathematics")
sms.display_students()
sms.remove_student("5678")
sms.display_students()
student = sms.search_student("1234")
if student:
print("Found student: Name: {}, ID Number: {}, Major: {}".format(student.name, student.id_number, student.major))
else:
print("Student not found.")
```
这是一个简单的面向对象的设计,包含学生类和学生管理系统类。学生管理系统类包含添加学生、删除学生、搜索学生和显示学生列表等功能。你可以根据需求扩展这个代码。
阅读全文