Question: There is a tets file which gives the expected output and the code proposed by the epxert is not providing that: import school _ group
There is a tets file which gives the expected output and the code proposed by the epxert is not providing that: import schoolgroupseparation
def verifyAnsfileNameInput fileNameOutput, ExpectedAnswer:
fileOut openfileNameOutputr
linesOut fileOut.readlines
fileOut.close
ifnot ExpectedAnswer:
iflinesOutstrip "impossible":
raise ExceptionWrong answer, should be impossible
else:
fileIn openfileNameInputr
linesIn fileIn.readlines
fileIn.close
nbStudents intlinesIn
students
ifnbStudents :
students sstrip for s in linesIn:nbStudents
nbPairs intlinesInnbStudents
pairs
ifnbPairs :
pairs linesInnbStudents:nbStudentsnbPairs
groupA setlinesOutstripsplit
groupB setlinesOutstripsplit
#each student is in the answer, and only in one group
for s in students:
ifs in groupAs in groupB:
ifs in groupA:
raise ExceptionStudent strs has been put in both groups"
else:
raise ExceptionStudent strs hasn't been put in any group"
#there are no extra students or duplicate:
iflengroupA lengroupB nbStudents:
raise ExceptionNumber of students in the output is strlengroupAlengroupB expected strnbStudents
#for every given pair, the students are in different groups
for p in pairs:
student student pstripsplit
ifstudent in groupA and student in groupA or student in groupB and student in groupB:
raise ExceptionStudents strstudent and strstudent cannot be in the same group"
if namemain:
expected True False, True, False, False, True, True, True, False, True, False
for i in rangelenexpected:
try:
fileIn "input" stritxt
fileOut "output" stritxt
schoolgroupseparation.mainfileIn fileOut
verifyAnsfileIn fileOut, expectedi
printTest stri OK
except Exception as e:
printTest stri Fail"
printe
print
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
