Answer:
class Question:
def __init__(self):
self.text = ""
self.answer = ""
def setText(self,text):
self.text = text
def setAnswer(self,answer):
self.answer = answer
def display(self):
print(self.text)
def checkAnswer(self,response):
ans = self.answer.replace(' ','')
ans = ans.lower()
response = response.replace(' ','')
response = response.lower()
if(response == ans):
return "Correct answer"
else:
return "Wrong answer"
class FillInQuestion (Question):
def __init__(self):
super(Question, self).__init__()
def setText(self,text):
temp = text.split("_")
temp[0] = temp[0] + "_______"
super(FillInQuestion,self).setText(temp[0])
super(FillInQuestion, self).setAnswer(temp[1])
def main():
# 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))
main()
Explanation:
The python program defines two classes, a parent class called Question and a child class called FillInQuestion. The screen shot of the output is seen below.