Question: IN PYTHON Add a class FillInQuestion to the following code. Such a question is constructed with a string that contains the answer, surrounded by _
IN PYTHON Add a class FillInQuestion to the following code. Such a question is constructed with a string that contains the answer, surrounded by _ _, for example, the inventor of Python was _Guido van Rossum_. The question should be displayed as The inventor of Python was _______ Below is the program that runs the modified class Question: ## # Demonstrate the FillInQuestion class. # # Create the question and expected answer. q = FillInQuestion() q.setText("The inventor of Python was _Guido van Rossum_") # Display the question and obtain user's response. q.display() response = input("Your answer: ") print(q.checkAnswer(response))
class Question :
def __init__(self) : self._text = "" self._answer = ""
def setText(self, questionText) self._text = questionText def setAnswer(self, correctResponse) : self._answer = correctResponse def checkAnswer(self, response): return response == self._answer def display(self): print(self._text)
##############################################
Below is the program that runs the modified class Question:
##
# Demonstrate the FillInQuestion class.
#
# Create the question and expected answer.
q = FillInQuestion()
q.setText("The inventor of Python was _Guido van Rossum_")
# Display the question and obtain user's response.
q.display()
response = input("Your answer: ")
print(q.checkAnswer(response))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
