class Exam:
    def __init__(self, name):
        self.name = name
        self.questions = []

    def AddQuestion(self, q):
        self.questions.append(q)

    def Print(self):
        print(self.name)
        count = 1
        for q in self.questions:
            print("%d. %s"%(count,q))
            print()
            count += 1
            
    def PrintAnswerKey(self):
        print(self.name)
        count = 1
        for q in self.questions:
            print( "%d. %s"%(count,q) )
            print( "  Answer: %s"%q.getAnswer())
            print()
            count += 1
            
class Question:
    def __init__(self, question):
        self.question = question
        self.answer = ""

    def __str__(self):
        return self.question

    def getAnswer(self):
        return self.answer

    def setAnswer(self, a):
        self.answer = a
        
class MultipleChoiceQuestion( Question ):
    def __init__(self, q):
        self.options = []
        self.q = q
        self.answer = "a"

    def SetOption(self, option):
        self.options.append(option)

    def SetAnswer(self, a):
        for opt in self.options:
            if a == opt[0]:
                self.answer = "%s. %s"%(opt[0], opt[1])
                return
        print( "bad option" )
        
    def Format( self ):
        self.question = "%s\n"%self.q
        for opt in self.options:
            self.question = self.question+"    %s. %s"%(opt[0], opt[1])
            if opt != self.options[-1]:
                self.question = self.question+"\n"

def main():
    e = Exam( "Exam 2" )
    q = Question( "Why is there air? " )
    q.setAnswer( "A 'self.' variable.' \n   There is a copy for each object of the class." )
    e.AddQuestion(q)
    q = Question( "What is self? " )
    q.setAnswer( "Whatever object is being referred to." )
    e.AddQuestion(q)
    q = Question( "What is an object? " )
    q.setAnswer( "One instance of a class." )
    e.AddQuestion(q)
    q = MultipleChoiceQuestion( "What is 3+5?" )
    q.SetOption( ("a", "4") )
    q.SetOption(  ("b", "35") )
    q.SetOption( ("c", "8" ))
    q.SetAnswer( "c" )
    q.Format()
    e.AddQuestion(q)
    q = MultipleChoiceQuestion(  "What is your favorite lab?" )
    q.SetOption( ("A", "Lab 5: Recursion" ))
    q.SetOption(  ("B", "Lab 7: Distill and Anagrams" ))
    q.SetOption( ("C", "Lab 8: Scavenger Hunt" ))
    q.SetOption( ("D", "Lab 9: Sound Synthesis" ))
    q.SetAnswer( "A" )
    q.Format()
    e.AddQuestion(q)

    e.Print()
    print( "#########################" )
    e.PrintAnswerKey()

main()

    
