Question: from __future__ import annotations from typing import TYPE_CHECKING, Union, Dict, List from criterion import HomogeneousCriterion, InvalidAnswerError if TYPE_CHECKING: from criterion import Criterion from grouper import

from __future__ import annotations from typing import TYPE_CHECKING, Union, Dict, List from criterion import HomogeneousCriterion, InvalidAnswerError if TYPE_CHECKING: from criterion import Criterion from grouper import Grouping from course import Student

class Question: """ An abstract class representing a question used in a survey

=== Public Attributes === id: the id of this question text: the text of this question

=== Representation Invariants === text is not the empty string """

def __init__(self, id_: int, text: str) -> None: """ Initialize a question with the text """ raise NotImplementedError

def __int__(self) -> int: """ Return the id of the question. """ raise NotImplementedError

def __str__(self) -> str: """ Return a string representation of this question that contains both the text of this question and a description of all possible answers to this question.

You can choose the precise format of this string. """ raise NotImplementedError

def validate_answer(self, answer: Answer) -> bool: """ Return True iff is a valid answer to this question. """ raise NotImplementedError

def get_similarity(self, answer1: Answer, answer2: Answer) -> float: """ Return a float between 0.0 and 1.0 indicating how similar two answers are.

=== Precondition === and are both valid answers to this question """ raise NotImplementedError

class MultipleChoiceQuestion(Question): """ A question whose answers can be one of several options

=== Public Attributes === id: the id of this question text: the text of this question

=== Representation Invariants === text is not the empty string """

id: int text: str options: List[str]

def __init__(self, id_: int, text: str, options: List[str]) -> None: """ Initialize a question with the text and id and possible answers .

=== Precondition === No two elements in are the same string contains at least two elements """ self.id = id_ self.text = text self.options = options

def __int__(self) -> int: """ Return the id of the question. """ return self.id

def __str__(self) -> str: """ Return a string representation of this question including the text of the question and a description of the possible answers.

You can choose the precise format of this string. """ return self.text + ": " + self.options

def validate_answer(self, answer: Answer) -> bool: """ Return True iff is a valid answer to this question.

An answer is valid if its content is one of the possible answers to this question. """ # TODO: complete the body of this method

def get_similarity(self, answer1: Answer, answer2: Answer) -> float: """ Return 1.0 iff .content and .content are equal and 0.0 otherwise.

=== Precondition === and are both valid answers to this question. """ # TODO: complete the body of this method

class Answer: """ An answer to a question used in a survey

=== Public Attributes === content: an answer to a single question """ content: Union[str, bool, int, List[str]]

def __init__(self, content: Union[str, bool, int, List[Union[str]]]) -> None: """Initialize an answer with content """ # TODO

def is_valid(self, question: Question) -> bool: """Return True iff self.content is a valid answer to """ return Question.validate_answer(question, self.content)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!