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)
16 if question.multiline:
23 a = answer.strip().lower()
24 if a in ['q', 'quit']:
27 if a in ['?', 'help']:
29 print(question.prompt)
32 if question.multiline:
33 answers.append(answer)
38 if question.multiline:
40 correct = self.process_answer(question=question, answer=answer)
46 def display_results(self):
48 for question in self.quiz:
49 if question.id in self.answers:
50 self.display_result(question=question)
54 def display_result(self, question):
55 answers = self.answers.get(question.id, [])
56 print('question: {}'.format(question.prompt))
58 lc = len([a for a in answers if a['correct']])
59 print('answers: {}/{} ({:.2f})'.format(lc, la, float(lc)/la))
60 for answer in answers:
65 print(' you answered: {}'.format(answer['answer']))
66 print(' which was: {}'.format(correct))
68 def display_totals(self):
69 answered = self.answers.get_answered(questions=self.quiz)
70 correctly_answered = self.answers.get_correctly_answered(
73 lc = len(correctly_answered)
74 print('answered {} of {} questions'.format(la, len(self.quiz)))
75 print(('of the answered questions, {} ({:.2f}) were answered correctly'
76 ).format(lc, float(lc)/la))