Question
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
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. """ return 'Question : '+self.text
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.
Preconditions: -
class CheckboxQuestion: # TODO: make this a child class of another class defined in this file """A question whose answers can be one or more 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 """ id: int text: str
def __init__(self, id_: int, text: str, options: list[str]) -> None: """Initialize this question with the text
def __str__(self) -> str: """Return a string representation of this question including the text of the question and a description of the possible answers.
""" # TODO: implement this method or remove it (to inherit it as is)
def validate_answer(self, answer: Answer) -> bool: """Return True iff
An answer is valid iff: * It is a non-empty list. * It has no duplicate entries. * Every item in it 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 the similarity between
Similarity is defined as the ratio between the number of strings that are common to both
For example, if
Preconditions: -
=== Public Attributes === """ content: Union[str, bool, int, list[str]]
def __init__(self, content: Union[str, bool, int, list[str]]) -> None: """Initialize this answer with content
def is_valid(self, question: Question) -> bool: """Return True iff this answer is a valid answer to
class Survey: """A survey containing questions as well as criteria and weights used to evaluate the quality of a group based on their answers to the survey questions.
=== Private Attributes === _questions: a dictionary mapping a question's id to the question itself _criteria: a dictionary mapping a question's id to its associated criterion _weights: a dictionary mapping a question's id to a weight -- an integer representing the importance of this criteria.
=== Representation Invariants === No two questions on this survey have the same id Each key in _questions equals the id attribute of its value The dictionaries _questions, _criteria, and _weights all have the same keys Each value in _weights is greater than 0
NOTE: The weights associated with the questions in a survey do NOT have to sum up to any particular amount. """ _questions: dict[int, Question] _criteria: dict[int, Criterion] _weights: dict[int, int]
def __init__(self, questions: list[Question]) -> None: """Initialize a new survey that contains every question in
This new survey should use a HomogeneousCriterion as a default criterion and should use 1 as a default weight. """ # TODO: implement this method!
def __len__(self) -> int: """Return the number of questions in this survey """ # TODO: implement this method!
def __contains__(self, question: Question) -> bool: """Return True iff there is a question in this survey with the same id as
def __str__(self) -> str: """Return a string containing the string representation of all questions in this survey.
You can choose the precise format of this string. """ # TODO: implement this method!
def get_questions(self) -> list[Question]: """Return a list of all questions in this survey """ # TODO: implement this method!
def _get_criterion(self, question: Question) -> Criterion: """Return the criterion associated with
Preconditions: -
def _get_weight(self, question: Question) -> int: """Return the weight associated with
Preconditions: -
def set_weight(self, weight: int, question: Question) -> bool: """Set the weight associated with
If
def set_criterion(self, criterion: Criterion, question: Question) -> bool: """Set the criterion associated with
If
def score_students(self, students: list[Student]) -> float: """Return a quality score for
The score is determined using the following algorithm: 1. For each question in this survey, find the question's associated criterion (do we want homogeneous answers, for instance), weight, and
This method should NOT throw an InvalidAnswerError. If one occurs during the execution of this method or if there are no questions in
Preconditions: - All students in
def score_grouping(self, grouping: Grouping) -> float: """Return a score for
If there are no groups in
Preconditions: - All students in the groups in
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