Question: coding language is Python 3.8, the TODO's are what need to be completed class Question: An abstract class representing a question used in a







coding language is Python 3.8, the TODO's are what need to be completed
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 TE DI id: int text: str def init__(self, id_: int, text: str) -> None: " Initialize a question with the text " self.question = text 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. HEIT '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 === Kanswer1> and are both valid answers to this question TENTI 'raise NotImplementedError Jclass MultipleChoiceQuestion: # TODO: make this a child class of another class defined in this file " 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 HIE id: int text: str definit__(self, id_: int, text: str, options: List[str]) -> None: Initialize a question with the text and id and possible answers contains at least two elements # TODO: complete the body of this method 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. # TODO: complete the body of this method def validate_answer(self, answer: Answer) -> bool: Return True iff float: Return 1.0 iff . content and . content are equal and 0.0 otherwise. === Precondition === and are both valid answers to this question. FT TE TE # TODO: complete the body of this method class NumericQuestion: # TODO: make this a child class of another class defined in this file " A question whose answer can be an integer between some minimum and maximum value (inclusive). === Public Attributes === id: the id of this question text: the text of this question === Representation Invariants === text is not the empty string HETETT id: int text: str HT GT- def __init_(self, id_: int, text: str, min_: int, max_: int) -> None: Initialize a question with id and text whose possible answers can be any integer between and (inclusive) === Precondition === min_ 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. # TODO: complete the body of this method def validate_answer(self, answer: Answer) -> bool: Return True iff the content of is an integer between the minimum and maximum (inclusive) possible answers to this question. # TODO: complete the body of this method def get_similarity(self, answer1: Answer, answer2: Answer) -> float: Return the similarity between and over the range of possible answers to this question. Similarity calculated by: 1. first find the absolute difference between . content and . content. 2. divide the value from step 1 by the difference between the maximimum and minimum possible answers. 3. subtract the value from step 2 from 1.0 Hint: this is the same calculation from the worksheet in Lecture! For example: Eclass 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]ll) -> None: "Initialize an answer with content """ # TODO: complete the body of this method def is_valid(self, question: Question) -> bool: "Return True iff self.content is a valid answer to "". # TODO: complete the body of this method