From 2d477ae11b05e44d61e624490476e017bae7420f Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 5 Feb 2013 09:19:36 -0500 Subject: [PATCH] Display results (but not the correct answers) --- quizzer/cli.py | 1 + quizzer/ui/__init__.py | 3 +++ quizzer/ui/cli.py | 16 ++++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/quizzer/cli.py b/quizzer/cli.py index 9eab5d0..6faf1cb 100644 --- a/quizzer/cli.py +++ b/quizzer/cli.py @@ -24,3 +24,4 @@ def main(): quiz.load() ui = _cli.CommandLineInterface(quiz=quiz) ui.run() + ui.display_results() diff --git a/quizzer/ui/__init__.py b/quizzer/ui/__init__.py index 43c1502..3dc520e 100644 --- a/quizzer/ui/__init__.py +++ b/quizzer/ui/__init__.py @@ -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: diff --git a/quizzer/ui/cli.py b/quizzer/ui/cli.py index ed40862..797a215 100644 --- a/quizzer/ui/cli.py +++ b/quizzer/ui/cli.py @@ -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() -- 2.26.2