Question
Python: A class Question is designed to models xam questions. Please implement the class with the following functions: def __init__ (self) : #constructs a question
Python: A class Question is designed to models xam questions. Please implement the class with the following functions:
def __init__ (self) : #constructs a question with empty question and answer strings.
def setText (self, questionText) : #set the question text
def setAnswser(self, correctResponse) : #set answer for this question
def checkAnswer(self, response) : #check if a given answer is correct or not
def display(self) : display the question
Also, a ChoiceQuestion class inherits from the Question class, that could handle multiple choices like the following:
In which country the inventor of Python born?
Australia 2. Canada 3. Netherlands 4. United States
The subclass has its own constructor (self._choice = []), a new method addChoice (self, choice, correct) will be added. For example,
question.addChoice(Canada, False)
question.addChoice(Netherlands, True)
#in this case, you will set answer to 3 by calling the base function setAnswer(3).
It also overrides the display function.
Testing: Play with the above using questions such as:
Question: What is Python Answer: A programming language User response: various
The above choice question
Add a number of your testings.
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