From 21d1f9e915c3c952c407f7cce9924ecdd6437ed8 Mon Sep 17 00:00:00 2001 From: Miguel Barão Date: Sun, 18 Nov 2018 16:18:41 +0000 Subject: [PATCH] accept numerical answers using comma as a decimal separator (as alternative to the dot) --- questions.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/questions.py b/questions.py index ac34577..f871fb0 100644 --- a/questions.py +++ b/questions.py @@ -299,15 +299,9 @@ class QuestionNumericInterval(Question): super().correct() if self['answer'] is not None: lower, upper = self['correct'] - try: - answer = float(self['answer']) - - # TODO: - # alternative using locale (1.2 vs 1,2) - # import locale - # locale.setlocale(locale.LC_ALL, 'pt_PT') - # answer = locale.atof(self['answer']) + try: # replace , by . and convert to float + answer = float(self['answer'].replace(',', '.', 1)) except ValueError: self['comments'] = 'A resposta não é numérica.' self['grade'] = 0.0 -- libgit2 0.21.2