From a39b2eb914bed1722877da50260a3b44f61f41f5 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 14 Feb 2013 09:17:08 -0500 Subject: [PATCH] ui.cli: Avoid divide-by-zero errors if no questions were answered --- quizzer/ui/cli.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/quizzer/ui/cli.py b/quizzer/ui/cli.py index 7d7c701..4a0fa49 100644 --- a/quizzer/ui/cli.py +++ b/quizzer/ui/cli.py @@ -162,7 +162,8 @@ class CommandLineInterface (UserInterface): question.format_prompt(newline='\n ')))) la = len(answers) lc = len([a for a in answers if a['correct']]) - print('answers: {}/{} ({:.2f})'.format(lc, la, float(lc)/la)) + if la: + print('answers: {}/{} ({:.2f})'.format(lc, la, float(lc)/la)) for answer in answers: if answer['correct']: correct = 'correct' @@ -182,5 +183,7 @@ class CommandLineInterface (UserInterface): 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)) + if la: + print(('of the answered questions, ' + '{} ({:.2f}) were answered correctly' + ).format(lc, float(lc)/la)) -- 2.26.2