Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PYTHON PLEASE. Add a class MultiChoiceQuestion to the question hierarcy of secti

ID: 3574609 • Letter: P

Question

PYTHON PLEASE. Add a class MultiChoiceQuestion to the question hierarcy of section 10.1 that allows multiple correct choices. The respondant should provide all correct choices, separated by spaces. Provide instructions in the question text. Below is the program that truns the class MultiChoiceQuestion.

q = MultiChoiceQuestion()
q.setText("Of Apple, Tomato, Carrot, Cucumber, and Celery, list all that are fruit.")
q.setAnswer("Apple Tomato")

q.display()
response = input ("your answer: ")
print(q.checkAnswer(response))

Section 10.1 class

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, reponse):
return response = self._answer

def display(self):
print(self._text)

Explanation / Answer

class MultiChoiceQuestion:

    #constructor

    def __init__(self):

      print ''

    #setText method

    def setText(self, quesionn):

        self.quesionn=quesionn

    #setAnswer method

    def setAnswer(self,answwerr):

        self.answwerr=answwerr

    #display method

    def display(self):

        print self.quesionn

    #checkAnswer method

    def checkAnswer(self,response):

        s1 = 'abc def ghi'

        s2 = 'def ghi abc'

        set1 = set(response.split(' '))

        set2 = set(self.answwerr.split(' '))

        return set1 == set2

q = MultiChoiceQuestion()

q.setText("Of Apple, Tomato, Carrot, Cucumber and Celery, list all that are fruit.")

q.setAnswer("Apple Tomato")

q.display()

response= input("Your answer: ")

response="Apple Tomato"

print(q.checkAnswer(response))

Sample Output :

Of Apple, Tomato, Carrot, Cucumber and celery, list all that are fruit.

Your answer: Apple Tomato

True