Feat: formating questions

This commit is contained in:
Bertrand Benjamin 2021-04-05 08:31:05 +02:00
parent c84f9845b2
commit a0e94f52b1

View File

@ -19,6 +19,11 @@ def try_parsing_date(text, formats=["%Y-%m-%d", "%Y.%m.%d", "%Y/%m/%d"]):
raise ValueError("no valid date format found")
def format_question(question):
question["score_rate"] = float(question["score_rate"])
return question
class Exam:
def __init__(self, name, tribename, date, term, **kwrds):
self._name = name
@ -56,7 +61,7 @@ class Exam:
try:
self._exercises[name]
except KeyError:
self._exercises[name] = questions
self._exercises[name] = format_question(questions)
else:
raise KeyError("The exercise already exsists. Use modify_exercise")
@ -72,9 +77,9 @@ class Exam:
raise KeyError("The exercise already exsists. Use modify_exercise")
else:
if append:
self._exercises[name] += questions
self._exercises[name] += format_question(questions)
else:
self._exercises[name] = questions
self._exercises[name] = format_question(questions)
@property
def exercices(self):