you are an expert in python programming and your role is to write python scripts. i am…
- User
you are an expert in python programming and your role is to write python scripts.
i am in charge of managing teachers distribution between classrooms for exam surveillance. there are 24 classroms and 55 teachers. the exam will be on 7 subjects. write a script that does the following: for each subject, create 24 random teacher pairs and assign each pair to a classroom. the remaining teachers should be assigned to a classrom named "REST". the teachers should not get paired with each other more than once throughout the 7 subjects the teachers should not be assigned to the same classroom more than once throughout the 7 subjects each teacher should be assigned to the "REST" classroom at least once in one of the subjects.
output example: {"SUBJECT-1": { "classroom-1" : ["teacher-1","teacher-3"], "classroom-2" : ["teacher-4","teacher-6"]], "REST": ["teacher8","teacher-9","teacher-10"] }, "SUBJECT-2": { "classroom-1" : ["teacher-5","teacher-8"], "classroom-2" : ["teacher-12","teacher-11"]], "REST": ["teacher34","teacher-22","teacher-45"] }, }
- Assistant
import random
def create_teacher_pairs(teachers): random.shuffle(teachers) return [teachers[i:i + 2] for i in range(0, len(teachers), 2)]
def distribute_teachers(teachers, exam_subjects, classrooms): distribution = {} paired_teachers = set() classroom_assignments = {teacher: set() for teacher in teachers}
for subject in range(1, exam_subjects + 1): pairs = create_teacher_pairs(teachers) while any(tuple(sorted(pair)) in paired_teachers for pair in pairs): pairs = create_teacher_pairs(teachers) for pair in pairs: paired_teachers.add(tuple(sorted(pair))) assigned_classrooms = set() subject_distribution = {} for i, pair in enumerate(pairs[:classrooms]): classroom = "classroom-" + str(i + 1) while classroom in assigned_classrooms or any(classroom in classroom_assignments[teacher] for teacher in pair): classroom = "classroom-" + str(random.randint(1, classrooms)) subject_distribution[classroom] = pair for teacher in pair: classroom_assignments[teacher].add(classroom) assigned_classrooms.add(classroom) remaining_teachers = teachers[(classrooms*2):] if not any("REST" in classroom_assignments[teacher] for teacher in remaining_teachers): subject_distribution["REST"] = remaining_teachers for teacher in remaining_teachers: classroom_assignments[teacher].add("REST") distribution["SUBJECT-" + str(subject)] = subject_distribution return distribution