Assembling Classes
Thomas J. Kennedy
1 The Problem
Developing questions for quizzes, exams and similar assessments is often difficult. Questions need to have…
-
multiple variants
-
feedback for correct answers
-
feedback for incorrect answers
-
possible points
Our goal is to work with question pools (i.e., groups of related questions). We want to build a few classes…
The two builder classes will be handled by another team. (i.e., they will be provided). Your work will focus on EssayQuestion
and QuestionPool
. We will pretend that EssayQuestion
is the only type of question.
This will be a two-part exercise. This assignment will focus on EssayQuestion
and the next assignment will focus on QuestionPool
.
1.1 Input
There is no input to this program.
1.2 Output
There is no main
function in this program. the EssayQuestion
class will evaluated with a test suite within tests/test_essay_quesion.py
.
2 Your Tasks
Your task is to create the EssayQuestion
class as documented in the UML Class diagram within the The Problem section. You may either:
-
implement the
EssayQuestion
class from scratch with a basic class -
implement the
EssayQuestion
class with the@dataclass
decorator
Your implementation must result in an EssayQuestion
class with the following data members:
-
question_text
- anstr
that contains the actual question text. -
feedback_correct
- an optionalstr
that provides feedback for correct answers. The default value must beNone
. -
feedback_incorrect
- an optionalstr
that provides feedback for incorrect answers. The default value must beNone
. -
points
- an optionalint
that provides the default point value for the question. The default value must be0
.
Your EssayQuestion
implementation must provide the following methods:
-
__init__
- the standard constructor. It must accept a singlestr
parameter (title) which serves as the question text. -
__eq__
- compares twoEssayQuestion
objects by comparing question text and no other fields. -
__repr__
- generates debugging output. Your implementation must generate output in the following form…EssayQuestion( question_text="...", feedback_correct="...", feedback_incorrect="...", points=... )
The ellipses are placeholders for the actual values.
-
__str__
- generates production output. Your implementation must generate output in the following form…Points: [points] [Question Text] Feedback: Correct: [feedback] Incorrect: [feedback]
The items denoted be square brackets are placeholders for the actual values.
3 Mechanics
The test code can be run with…
python3.11 -m pytest -v tests
4 Files
There are two (2) files in this assignment:
essay_question.py
test/test_essay_question.py
You will be working in essay_question.py
. Do not modify the other files.
You can access the starting files on GitHub. You may either clone the starting repository (through Git) or download a zip file.
5 Grading
Your grade will be based on the following criteria…
- test 000 - code passes
test_all_fields_present
- test 001 - code passes
test_default_values
- test 002 - code passes
test_eq
- test 003 - code passes
test_repr
- test 004 - code passes
test_str
6 Submitting
You will submit your completed copy of essay_question.py
as a file upload through Canvas.
Do not alter any of the other source code files, nor change the module interface.