2 import readline as _readline
3 except ImportError as _readline_import_error:
6 from . import UserInterface
9 class CommandLineInterface (UserInterface):
12 question = self.get_question()
15 print(question.prompt)
21 a = answer.strip().lower()
22 if a in ['q', 'quit']:
25 if a in ['?', 'help']:
27 print(question.prompt)
31 correct = self.process_answer(question=question, answer=answer)
37 def display_results(self):
39 for question in self.quiz:
40 if question.id in self.answers:
41 self.display_result(question=question)
45 def display_result(self, question):
46 answers = self.answers.get(question.id, [])
47 print('question: {}'.format(question.prompt))
49 lc = len([a for a in answers if a['correct']])
50 print('answers: {}/{} ({:.2f})'.format(lc, la, float(lc)/la))
51 for answer in answers:
56 print(' you answered: {}'.format(answer['answer']))
57 print(' which was: {}'.format(correct))
59 def display_totals(self):
60 answered = self.answers.get_answered(questions=self.quiz)
61 correctly_answered = self.answers.get_correctly_answered(
64 lc = len(correctly_answered)
65 print('answered {} of {} questions'.format(la, len(self.quiz)))
66 print(('of the answered questions, {} ({:.2f}) were answered correctly'
67 ).format(lc, float(lc)/la))