diff --git a/moxquizz/quiz.py b/moxquizz/quiz.py index 0c5bfb6..a481deb 100644 --- a/moxquizz/quiz.py +++ b/moxquizz/quiz.py @@ -7,6 +7,7 @@ See http://moxquizz.de/ for the original implementation in TCL. from __future__ import unicode_literals, print_function from io import open +import re class Question: @@ -163,6 +164,9 @@ class Question: if 'Tipcycle' in attributes_dict.keys(): self.tipcycle = attributes_dict['Tipcycle'] + def attempt(self, answer): + return (self.answer is not None and self.answer.lower() == answer.lower()) or ( + self.regexp is not None and re.search(self.regexp, answer, re.IGNORECASE) is not None) class QuestionBank: """ @@ -287,7 +291,7 @@ if __name__ == '__main__': print(q.question) a = unicode(raw_input('A: '), 'utf8') #a = input('A: ') # Python 3 - if a.lower() == q.answer.lower(): + if q.attempt(a): print("Correct!") else: print("Incorrect - the answer is '%s'" % q.answer) diff --git a/questions.doctorlard.en b/questions.doctorlard.en index c9721cf..fbf1b7a 100644 --- a/questions.doctorlard.en +++ b/questions.doctorlard.en @@ -108,4 +108,7 @@ Question: What is the main ingredient of borscht? Answer: beetroot Author: DoctorLard - +Category: Geography +Question: In what mountain range is Kicking Horse Pass? +Answer: Rocky Mountains +Regexp: Rock(y|ies)