From 52ce4bb8bc6c9d0c5b5115ed48eab9f7d6b75f49 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 5 Feb 2013 13:54:18 -0500 Subject: [PATCH] question: Add ChoiceQuestion for one-of-several correct answers --- quizzer/question.py | 5 +++++ quizzes/monty-python.json | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/quizzer/question.py b/quizzer/question.py index 2dd57e9..34fe8c1 100644 --- a/quizzer/question.py +++ b/quizzer/question.py @@ -58,6 +58,11 @@ class NormalizedStringQuestion (Question): return self.normalize(answer) == self.normalize(self.answer) +class ChoiceQuestion (Question): + def check(self, answer): + return answer in self.answer + + class ScriptQuestion (Question): _state_attributes = Question._state_attributes + [ 'interpreter', diff --git a/quizzes/monty-python.json b/quizzes/monty-python.json index 894105e..13d6210 100644 --- a/quizzes/monty-python.json +++ b/quizzes/monty-python.json @@ -2,8 +2,12 @@ "version": "0.1", "questions": [ { + "class": "ChoiceQuestion", "prompt": "What is your name?", - "answer": "", + "answer": [ + "Sir Lancelot", + "Sir Robin" + ], "help": "This should be easy" }, { -- 2.26.2