ui.cli: Avoid divide-by-zero errors if no questions were answered
authorW. Trevor King <wking@tremily.us>
Thu, 14 Feb 2013 14:17:08 +0000 (09:17 -0500)
committerW. Trevor King <wking@tremily.us>
Thu, 14 Feb 2013 14:18:20 +0000 (09:18 -0500)
quizzer/ui/cli.py

index 7d7c70117907c889e417927cf9ed9a8ba6377c91..4a0fa496371c0a2042d21436a109c1ad4a20c152 100644 (file)
@@ -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))