question: Add ChoiceQuestion for one-of-several correct answers
authorW. Trevor King <wking@tremily.us>
Tue, 5 Feb 2013 18:54:18 +0000 (13:54 -0500)
committerW. Trevor King <wking@tremily.us>
Tue, 5 Feb 2013 18:54:18 +0000 (13:54 -0500)
quizzer/question.py
quizzes/monty-python.json

index 2dd57e906c2a92dbb8fee649949f29c51b437537..34fe8c125856cd6fb963701f2ef9fc62f56cb466 100644 (file)
@@ -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',
index 894105e627cea9702fc02b14d0d47a9b385baafa..13d62103af66e6839228982f803321fa68e9c4d2 100644 (file)
@@ -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"
                },
                {