Python创建一个学校管理系统,包括学校类、教师类、学生类和课程类。输入学生信息,老师信息,课程信息,能够对应进行打印。
时间: 2024-12-17 14:43:29 浏览: 8
在Python中,我们可以创建一个简单的学校管理系统来模拟这个场景,通过类和对象来组织数据和操作。这里是一个基础的示例:
```python
class School:
def __init__(self):
self.teachers = []
self.students = []
self.courses = []
def add_teacher(self, teacher):
self.teachers.append(teacher)
def add_student(self, student):
self.students.append(student)
def add_course(self, course):
self.courses.append(course)
def print_info(self):
for teacher in self.teachers:
print("Teacher:", teacher.name)
for student in self.students:
print("Student:", student.name, "Course:", student.course)
for course in self.courses:
print("Course:", course.title, "Teacher:", course.teacher)
class Teacher:
def __init__(self, name):
self.name = name
class Student:
def __init__(self, name, course):
self.name = name
self.course = course
class Course:
def __init__(self, title, teacher):
self.title = title
self.
阅读全文