Display results (but not the correct answers)
authorW. Trevor King <wking@tremily.us>
Tue, 5 Feb 2013 14:19:36 +0000 (09:19 -0500)
committerW. Trevor King <wking@tremily.us>
Tue, 5 Feb 2013 14:19:36 +0000 (09:19 -0500)
quizzer/cli.py
quizzer/ui/__init__.py
quizzer/ui/cli.py

index 9eab5d0af3c5128ae03df3fe09fd2c7152c4e5a0..6faf1cbf8b2eb8c55a86eb5ffd99f36a5cb10b4c 100644 (file)
@@ -24,3 +24,4 @@ def main():
     quiz.load()
     ui = _cli.CommandLineInterface(quiz=quiz)
     ui.run()
+    ui.display_results()
index 43c1502c74813288cc2b16d7e70821b1444774ed..3dc520e42e6b158aad7004545dd2bab701d789ed 100644 (file)
@@ -9,6 +9,9 @@ class UserInterface (object):
     def run(self):
         raise NotImplementedError()
 
+    def display_results(self):
+        raise NotImplementedError()
+
     def get_question(self):
         remaining = [q for q in self.quiz if q not in self.answers]
         if remaining:
index ed40862b21e87386c041e2f515c066a4a51a0f95..797a215527095ba551e20712aa2cf098d76bacfb 100644 (file)
@@ -24,3 +24,19 @@ class CommandLineInterface (UserInterface):
                 print('correct\n')
             else:
                 print('incorrect\n')
+
+    def display_results(self):
+        for question in self.quiz:
+            if question in self.answers:
+                for answer in self.answers[question]:
+                    self.display_result(question=question, answer=answer)
+
+    def display_result(self, question, answer):
+        if answer['correct']:
+            correct = 'correct'
+        else:
+            correct = 'incorrect'
+        print('question:     {}'.format(question.prompt))
+        print('you answered: {}'.format(answer['answer']))
+        print('which was:    {}'.format(correct))
+        print()