Commit e84100c24784f939ccb13956251abdec14b3a25b

Authored by Miguel Barao
1 parent 3f0b10f3
Exists in master and in 1 other branch dev

- fixed bug in checkbox question when correcting with [0,...,0].

Showing 1 changed file with 13 additions and 8 deletions   Show diff stats
questions.py
... ... @@ -266,16 +266,21 @@ class QuestionCheckbox(Question):
266 266 self['grade'] = 0.0
267 267 else:
268 268 # answered
269   - x = 0.0
  269 + sum_abs = sum(abs(p) for p in self['correct'])
  270 + if sum_abs < 1e-6: # in case correct: [0,0,0,0,0]
  271 + self['grade'] = 0.0
270 272  
271   - if self['discount']:
272   - for i, p in enumerate(self['correct']):
273   - x += p if str(i) in self['answer'] else -p
274   - self['grade'] = x / sum(abs(p) for p in self['correct'])
275 273 else:
276   - for i, p in enumerate(self['correct']):
277   - x += p if str(i) in self['answer'] else 0.0
278   - self['grade'] = x / sum(abs(p) for p in self['correct'])
  274 + x = 0.0
  275 +
  276 + if self['discount']:
  277 + for i, p in enumerate(self['correct']):
  278 + x += p if str(i) in self['answer'] else -p
  279 + else:
  280 + for i, p in enumerate(self['correct']):
  281 + x += p if str(i) in self['answer'] else 0.0
  282 +
  283 + self['grade'] = x / sum_abs
279 284  
280 285 return self['grade']
281 286  
... ...