我想将不同的课程附加到两个不同的教室中,但是它不断将相同的课程添加到两个教室中。这是我的 AddCourse 功能
已编辑
我根据您的建议修改了我的代码。
class Classroom:
"""I omitted part of the class for brevity"""
def __init__(self, Seed = None, ClassroomId = None, FirstCourseStartTime = None, LastCourseEndTime = None, CourseList = [], ProfessorList = []):
self.setFirstCourseStartTime(FirstCourseStartTime)
self.setLastCourseEndTime(LastCourseEndTime)
self.setCourseList(CourseList)
self.setProfessorList(ProfessorList)
self.setSeed(Seed)
self.setClassroomId(ClassroomId)
def addCourse(self, Course):
self.CourseList.append(Course)
def setCourseList(self, List):
self.CourseList = List
#the statements below are from a different file to run the code/class above
Classroom1 = Classroom(Seed = os.urandom(1024/8), FirstCourseStartTime = 8, LastCourseEndTime = 19.75)
Classroom2 = Classroom(Seed = os.urandom(1024/8), FirstCourseStartTime = 8, LastCourseEndTime = 19.75)
# Adding the courses to the classrooms
Classroom1.addCourse(Course0)
Classroom1.addCourse(Course1)
Classroom1.addCourse(Course2)
Classroom1.addCourse(Course3)
Classroom1.addCourse(Course4)
Classroom1.addCourse(Course5)
Classroom1.addCourse(Course6)
Classroom1.addCourse(Course7)
Classroom2.addCourse(Course8)
Classroom2.addCourse(Course9)
Classroom2.addCourse(Course10)
Classroom2.addCourse(Course11)
Classroom2.addCourse(Course12)
Classroom2.addCourse(Course13)
Classroom2.addCourse(Course14)
Classroom2.addCourse(Course15)