Question: from __future__ import annotations from typing import TYPE_CHECKING if TYPE_CHECKING: from survey import Question, Answer class InvalidAnswerError(Exception): Error that should be raised when an answer
from __future__ import annotations from typing import TYPE_CHECKING
if TYPE_CHECKING: from survey import Question, Answer
class InvalidAnswerError(Exception): """Error that should be raised when an answer is invalid for a given question. """
class Criterion: """An abstract class representing a criterion used to evaluate the quality of a group based on the group members' answers for a given question. """
def score_answers(self, question: Question, answers: list[Answer]) -> float: """Return score between 0.0 and 1.0 indicating how well the group of
Raise InvalidAnswerError if any answer in
Each implementation of this abstract class will measure satisfaction of a criterion differently. """ # TODO: implement this method!
class HomogeneousCriterion: # TODO: make this a child class of another class defined in this file """A criterion used to evaluate the quality of a group based on the group members' answers for a given question.
This criterion gives a higher score to answers that are more similar. """
def score_answers(self, question: Question, answers: list[Answer]) -> float: """Return a score between 0.0 and 1.0 indicating how similar the answers in
This score is calculated by finding the similarity of every combination of two answers in
Raise InvalidAnswerError if any answer in
Preconditions: - len(answers) > 0 """ # TODO: implement this method or remove it (to inherit it as is)
class HeterogeneousCriterion: # TODO: make this a child class of another class defined in this file """A criterion used to evaluate the quality of a group based on the group members' answers for a given question.
This criterion gives a higher score to answers that are more different. """
def score_answers(self, question: Question, answers: list[Answer]) -> float: """Return a score between 0.0 and 1.0 indicating how different the answers in
This score is calculated by finding the similarity of every combination of two answers in
Raise InvalidAnswerError if any answer in
Preconditions: - len(answers) > 0 """ # TODO: implement this method or remove it (to inherit it as is)
class LonelyMemberCriterion: # TODO: make this a child class of another class defined in this file """A criterion used to measure the quality of a group of students according to the group members' answers to a question.
This criterion gives a higher score to a group if no member of the group gives a unique answer to a question, that is, an answer that no other member gave.
This criterion could be used, for example, to avoid putting a student into a group where they are the only one from their college. """
def score_answers(self, question: Question, answers: list[Answer]) -> float: """Return score between 0.0 and 1.0 indicating the quality of the group of
The score returned will be 0.0 iff there are any unique answers in
Raise InvalidAnswerError if any answer in
Preconditions: - len(answers) > 0 """ # TODO: implement this method or remove it (to inherit it as is)
if __name__ == '__main__': import python_ta
python_ta.check_all(config={'extra-imports': ['typing', 'survey', 'E9992'], 'disable': ['E9992']})
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
