Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

from __future__ import annotations from typing import TYPE_CHECKING, List if TYPE_CHECKING: from survey import Question, Answer class InvalidAnswerError(Exception): Error that should be raised when

from __future__ import annotations from typing import TYPE_CHECKING, List 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 the quality of the group of to the question .

Raise InvalidAnswerError if any answer in is not a valid answer to .

Each implementation of this abstract class will measure quality differently. """ raise NotImplementedError

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 are.

This score is calculated by finding the similarity of every combination of two answers in and taking the average of all of these similarity scores.

If there is only one answer in and it is valid return 1.0 since a single answer is always identical to itself.

Raise InvalidAnswerError if any answer in is not a valid answer to .

=== Precondition === len(answers) > 0 """ # TODO: complete the body of this method

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 similar the answers in are.

This score is calculated by finding the similarity of every combination of two answers in , finding the average of all of these similarity scores, and then subtracting this average from 1.0

If there is only one answer in and it is valid, return 0.0 since a single answer is never identical to itself.

Raise InvalidAnswerError if any answer in is not a valid answer to .

=== Precondition === len(answers) > 0 """ # TODO: complete the body of this method

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 assumes that a group is of high quality if no member of the group gives a unique answer to a question. """

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 to the question .

The score returned will be zero iff there are any unique answers in and will be 1.0 otherwise.

An answer is not unique if there is at least one other answer in with identical content.

Raise InvalidAnswerError if any answer in is not a valid answer to .

=== Precondition === len(answers) > 0 """ # TODO: complete the body of this method

if __name__ == '__main__': import python_ta python_ta.check_all(config={'extra-imports': ['typing', 'survey']})

Can you help me with the #TODO using python3.8? I don't really know how to construct a child class like this. Thank you.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Performance Indexing In SQL Server

Authors: Jason Strate, Grant Fritchey

2nd Edition

1484211189, 9781484211182

More Books

Students also viewed these Databases questions