Commit 21d1f9e915c3c952c407f7cce9924ecdd6437ed8
1 parent
6bd5c006
Exists in
master
and in
1 other branch
accept numerical answers using comma as a decimal separator (as alternative to the dot)
Showing
1 changed file
with
2 additions
and
8 deletions
Show diff stats
questions.py
... | ... | @@ -299,15 +299,9 @@ class QuestionNumericInterval(Question): |
299 | 299 | super().correct() |
300 | 300 | if self['answer'] is not None: |
301 | 301 | lower, upper = self['correct'] |
302 | - try: | |
303 | - answer = float(self['answer']) | |
304 | - | |
305 | - # TODO: | |
306 | - # alternative using locale (1.2 vs 1,2) | |
307 | - # import locale | |
308 | - # locale.setlocale(locale.LC_ALL, 'pt_PT') | |
309 | - # answer = locale.atof(self['answer']) | |
310 | 302 | |
303 | + try: # replace , by . and convert to float | |
304 | + answer = float(self['answer'].replace(',', '.', 1)) | |
311 | 305 | except ValueError: |
312 | 306 | self['comments'] = 'A resposta não é numérica.' |
313 | 307 | self['grade'] = 0.0 | ... | ... |