利用python写一个学生管理系统 学生的信息有 姓名 年龄 学号 出生日期
时间: 2023-06-12 14:05:20 浏览: 106
好的,下面是一个简单的学生管理系统的代码示例:
```python
class Student:
def __init__(self, name, age, student_id, birth_date):
self.name = name
self.age = age
self.student_id = student_id
self.birth_date = birth_date
class StudentManager:
def __init__(self):
self.students = []
def add_student(self, student):
self.students.append(student)
def remove_student(self, student_id):
for student in self.students:
if student.student_id == student_id:
self.students.remove(student)
def get_student(self, student_id):
for student in self.students:
if student.student_id == student_id:
return student
return None
def print_all_students(self):
for student in self.students:
print("Name: {}, Age: {}, Student ID: {}, Birth Date: {}"
.format(student.name, student.age, student.student_id, student.birth_date))
# 创建一个学生管理系统对象
manager = StudentManager()
# 添加学生
student1 = Student("Tom", 18, "1001", "2003-01-01")
student2 = Student("Jack", 20, "1002", "2001-03-05")
manager.add_student(student1)
manager.add_student(student2)
# 打印所有学生信息
manager.print_all_students()
# 删除学生
manager.remove_student("1001")
# 获取学生信息
student = manager.get_student("1002")
if student:
print("Student Found: Name: {}, Age: {}, Student ID: {}, Birth Date: {}"
.format(student.name, student.age, student.student_id, student.birth_date))
else:
print("Student Not Found.")
```
这个学生管理系统使用了两个类:一个是 `Student` 类,表示学生信息;另一个是 `StudentManager` 类,表示学生管理系统。`StudentManager` 类中包含了添加、删除、获取学生信息以及打印所有学生信息的方法。你可以通过调用这些方法来管理学生信息。
阅读全文
相关推荐


















