Commit 21d1f9e915c3c952c407f7cce9924ecdd6437ed8

Authored by Miguel Barão
1 parent 6bd5c006
Exists in master and in 1 other branch dev

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
@@ -299,15 +299,9 @@ class QuestionNumericInterval(Question): @@ -299,15 +299,9 @@ class QuestionNumericInterval(Question):
299 super().correct() 299 super().correct()
300 if self['answer'] is not None: 300 if self['answer'] is not None:
301 lower, upper = self['correct'] 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 except ValueError: 305 except ValueError:
312 self['comments'] = 'A resposta não é numérica.' 306 self['comments'] = 'A resposta não é numérica.'
313 self['grade'] = 0.0 307 self['grade'] = 0.0