raise NotImplementedError()
def get_question(self):
- remaining = [q for q in self.quiz if q not in self.answers]
+ remaining = self.get_unanswered()
if remaining:
return remaining[0]
'correct': correct,
})
return correct
+
+ def get_answered(self):
+ return [q for q in self.quiz if q in self.answers]
+
+ def get_unanswered(self):
+ return [q for q in self.quiz if q not in self.answers]
+
+ def get_correctly_answered(self):
+ return [q for q in self.quiz
+ if True in [a['correct'] for a in self.answers.get(q, [])]]
+
+ def get_never_correctly_answered(self):
+ return [q for q in self.quiz
+ if True not in [a['correct'] for a in self.answers.get(q, [])]]
if question in self.answers:
for answer in self.answers[question]:
self.display_result(question=question, answer=answer)
+ self.display_totals()
def display_result(self, question, answer):
if answer['correct']:
print('you answered: {}'.format(answer['answer']))
print('which was: {}'.format(correct))
print()
+
+ def display_totals(self):
+ answered = self.get_answered()
+ correctly_answered = self.get_correctly_answered()
+ la = len(answered)
+ lc = len(correctly_answered)
+ print('answered {} of {} questions'.format(la, len(self.quiz)))
+ print(('of the answered questions, {} ({:.2f}) were answered correctly'
+ ).format(lc, float(lc)/la))