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
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
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 ===
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
=== Precondition === No two elements in
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
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
=== Precondition ===
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
def is_valid(self, question: Question) -> bool: """Return True iff self.content is a valid answer to
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started