Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

class Question: An abstract class representing a question used in a survey === Public Attributes === id: the id of this question text: the text

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 """ id: int text: str

def __init__(self, id_: int, text: str) -> None: """Initialize this question with the text .""" self.id = id_ self.text = 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. """ # TODO: implement this method!

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

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

Preconditions: - and are both valid answers to this question """ # TODO: implement this method! class 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

=== Private Attributes === TODO: Describe any private attributes you create here

=== Representation Invariants === text is not the empty string """ id: int text: str

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

Preconditions: - No two elements in are the same string - contains at least two elements """ # TODO: implement this method or remove it (to inherit it as is)

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: implement this method or remove it (to inherit it as is)

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 answer options for this question. """ # TODO: implement this method or remove it (to inherit it as is)

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

Preconditions: - and are both valid answers to this question. """ # TODO: implement this method or remove it (to inherit it as is) 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

=== Private Attributes === TODO: Describe any private attributes you create here

=== Representation Invariants === text is not the empty string """ id: int text: str

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)

Preconditions: - min_ < max_ """ # TODO: implement this method or remove it (to inherit it as is)

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: implement this method or remove it (to inherit it as is)

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: implement this method or remove it (to inherit it as is)

def get_similarity(self, answer1: Answer, answer2: Answer) -> float: """Return the similarity between and over the range of possible answers to this question.

Similarity is calculated as follows: 1. first find the absolute difference between .content and .content. 2. divide the value from step 1 by the difference between the maximum and minimum possible answers. 3. subtract the value of step 2 from 1.0

For example: - Maximum similarity is 1.0 and occurs when == - Minimum similarity is 0.0 and occurs when is the minimum possible answer and is the maximum possible answer (or vice versa).

Preconditions: - and are both valid answers to this question """ # TODO: implement this method or remove it (to inherit it as is) class YesNoQuestion: # TODO: make this a child class of another class defined in this file """A question whose answer is either yes (represented by True) or no (represented by False).

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

=== Private Attributes === TODO: Describe any private attributes you create here

=== Representation Invariants === text is not the empty string """ id: int text: str

def __init__(self, id_: int, text: str) -> None: """Initialize a question with the text and id . """ # TODO: implement this method or remove it (to inherit it as is)

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

You can choose the precise format of this string. """ # TODO: implement this method or remove it (to inherit it as is)

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 answer options for this question. """ # TODO: implement this method or remove it (to inherit it as is)

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

Preconditions: - and are both valid answers to this question. """ # 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', 'criterion', 'course', 'grouper'], 'disable': ['E9992']})

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

Database Concepts

Authors: David M. Kroenke, David J. Auer

7th edition

133544621, 133544626, 0-13-354462-1, 978-0133544626

More Books

Students also viewed these Databases questions