Initial commit.
This commit is contained in:
commit
52538dc5a6
2 changed files with 290 additions and 0 deletions
111
questions.doctorlard.en
Normal file
111
questions.doctorlard.en
Normal file
|
|
@ -0,0 +1,111 @@
|
||||||
|
########################################################
|
||||||
|
# DoctorLard's collection of random Moxquizz questions
|
||||||
|
########################################################
|
||||||
|
|
||||||
|
## Demo-Entry:
|
||||||
|
# ----------
|
||||||
|
# Category: History
|
||||||
|
# Question: Chinese philosopher (um 500 v. Chr.) ?
|
||||||
|
# Answer: Konfuzius
|
||||||
|
# Regexp: [ck]onfu(ts|z)ius
|
||||||
|
# Author: anonymous
|
||||||
|
# Level: hard
|
||||||
|
# Comment: demo-entry, ÄÖÜäöüß ^° !"§$%&/()=? `Ž
|
||||||
|
# Score: 5
|
||||||
|
# Tip: Kon......
|
||||||
|
# Tip: ...fuz...
|
||||||
|
# Tip: ......ius
|
||||||
|
|
||||||
|
## valid keys:
|
||||||
|
# ----------
|
||||||
|
# Category? (should always be on top!)
|
||||||
|
# Question (should always stand after Category)
|
||||||
|
# Answer (will be matched if no regexp is provided)
|
||||||
|
# Regexp? (use UNIX-style expressions)
|
||||||
|
# Author? (the brain behind this question)
|
||||||
|
# Level? [baby|easy|normal|hard|extreme] (difficulty)
|
||||||
|
# Comment? (comment line)
|
||||||
|
# Score? [#] (credits for answering this question)
|
||||||
|
# Tip* (provide one or more hints)
|
||||||
|
# TipCycle? [#] (Specify number of generated tips)
|
||||||
|
|
||||||
|
## WARNING:
|
||||||
|
# -------
|
||||||
|
# DO NOT ADD COMMENTS BEYOND THIS LINE, since they might get lost.
|
||||||
|
# you may add as much comments as you want into the part above
|
||||||
|
|
||||||
|
Category: Temporal anomalies
|
||||||
|
Question: How many times do the minute and hour hands on a clockface overlap in a 24 hour period?
|
||||||
|
Answer: 22
|
||||||
|
Author: DoctorLard
|
||||||
|
|
||||||
|
Category: xG
|
||||||
|
Question: Which country did hell- visit in August 2014?
|
||||||
|
Answer: USA
|
||||||
|
Author: DoctorLard
|
||||||
|
|
||||||
|
Category: Music
|
||||||
|
Question: A traditional Arabian and Turkish string instrument, distinguished from the lute by having no frets.
|
||||||
|
Answer: oud
|
||||||
|
Author: Bill Bailey
|
||||||
|
|
||||||
|
Category: Pharmacology
|
||||||
|
Question: In Breaking Bad, Walter and Jesse used a "P2P cook" process to make very pure methamphetamine (by reduction with methylamine over aluminium). What does P2P stand for?
|
||||||
|
Answer: phenyl-2-propanone
|
||||||
|
Author: DoctorLard
|
||||||
|
|
||||||
|
Category: General ignorance
|
||||||
|
Question: What are igloos normally made of?
|
||||||
|
Answer: animal skins
|
||||||
|
Regexp: (animal )?skins
|
||||||
|
Tip: It isn't snow.
|
||||||
|
Tip: It isn't any form of frozen water.
|
||||||
|
Author: DoctorLard
|
||||||
|
|
||||||
|
Category: New Zealand
|
||||||
|
Question: In what year did New Zealand become self-governing (by gaining its own representative government, separate from the United Kingdom)?
|
||||||
|
Answer: 1852
|
||||||
|
Author: DoctorLard
|
||||||
|
|
||||||
|
Category: Geography
|
||||||
|
Question: How many of the Commonwealth of Nations' member states are Realms?
|
||||||
|
Answer: 16
|
||||||
|
Level: hard
|
||||||
|
Author: DoctorLard
|
||||||
|
|
||||||
|
Category: Sculpture
|
||||||
|
Question: Which Lord of the Rings actor, in an interview with Jay Leno, admitted to urinating in Wellington's Bucket Fountain sculpture while filming in New Zealand?
|
||||||
|
Answer: Elijah Wood
|
||||||
|
Author: DoctorLard
|
||||||
|
|
||||||
|
Category: TV
|
||||||
|
Question: Which British comedy actor played Richmond in The IT Crowd, and Vincent Noir in The Mighty Boosh?
|
||||||
|
Answer: Noel Fielding
|
||||||
|
Author: DoctorLard
|
||||||
|
|
||||||
|
Category: Video Games
|
||||||
|
Question: Who composed the music for the Elder Scrolls and Guild Wars games, thinks he's God's gift to composers, and takes fucking ages to ship CDs of his soundtracks?
|
||||||
|
Answer: Jeremy Soule
|
||||||
|
Author: DoctorLard
|
||||||
|
|
||||||
|
Category: Video Games
|
||||||
|
Question: In the Guild Wars world of Tyria, name the once great human kingdom, laid waste by the Charr?
|
||||||
|
Answer: Ascalon
|
||||||
|
Author: DoctorLard
|
||||||
|
|
||||||
|
Category: Video Games
|
||||||
|
Question: In Mass Effect 2 and 3, which Oscar-nominated American actor provided the voice for The Illusive Man?
|
||||||
|
Answer: Martin Sheen
|
||||||
|
Author: DoctorLard
|
||||||
|
|
||||||
|
Category: Cuisine
|
||||||
|
Question: Which spice is made from the dried and ground aril that surrounds a nutmeg (Myristica fragrans) seed?
|
||||||
|
Answer: Mace
|
||||||
|
Author: DoctorLard
|
||||||
|
|
||||||
|
Category: Cuisine
|
||||||
|
Question: What is the main ingredient of borscht?
|
||||||
|
Answer: beetroot
|
||||||
|
Author: DoctorLard
|
||||||
|
|
||||||
|
|
||||||
179
quiz.py
Normal file
179
quiz.py
Normal file
|
|
@ -0,0 +1,179 @@
|
||||||
|
## -*- coding: utf-8 -*-
|
||||||
|
import sys
|
||||||
|
if sys.version_info[0] < 3:
|
||||||
|
raise RuntimeError("Python 3 required.")
|
||||||
|
|
||||||
|
|
||||||
|
class Question:
|
||||||
|
"""
|
||||||
|
Represents one MoxQuizz question.
|
||||||
|
"""
|
||||||
|
|
||||||
|
category = None
|
||||||
|
question = None
|
||||||
|
answer = None
|
||||||
|
regexp = None
|
||||||
|
author = None
|
||||||
|
level = None
|
||||||
|
comment = None
|
||||||
|
score = 0
|
||||||
|
tip = list()
|
||||||
|
tipcycle = 0
|
||||||
|
|
||||||
|
TRIVIAL = 1
|
||||||
|
EASY = 2
|
||||||
|
NORMAL = 3
|
||||||
|
HARD = 4
|
||||||
|
EXTREME = 5
|
||||||
|
|
||||||
|
LEVELS = (TRIVIAL, EASY, NORMAL, HARD, EXTREME)
|
||||||
|
|
||||||
|
def __init__(self, attributes_dict):
|
||||||
|
self.parse(attributes_dict)
|
||||||
|
|
||||||
|
def parse(self, attributes_dict):
|
||||||
|
"""
|
||||||
|
Populate fields from a dictionary of attributes (from a question bank).
|
||||||
|
"""
|
||||||
|
|
||||||
|
## Valid keys:
|
||||||
|
# ----------
|
||||||
|
# Category? (should always be on top!)
|
||||||
|
# Question (should always stand after Category)
|
||||||
|
# Answer (will be matched if no regexp is provided)
|
||||||
|
# Regexp? (use UNIX-style expressions)
|
||||||
|
# Author? (the brain behind this question)
|
||||||
|
# Level? [baby|easy|normal|hard|extreme] (difficulty)
|
||||||
|
# Comment? (comment line)
|
||||||
|
# Score? [#] (credits for answering this question)
|
||||||
|
# Tip* (provide one or more hints)
|
||||||
|
# TipCycle? [#] (Specify number of generated tips)
|
||||||
|
|
||||||
|
if 'Question' in attributes_dict.keys():
|
||||||
|
self.question = attributes_dict['Question']
|
||||||
|
else:
|
||||||
|
raise Exception("Cannot instantiate Question: 'Question' attribute required.")
|
||||||
|
|
||||||
|
if 'Category' in attributes_dict.keys():
|
||||||
|
self.category = attributes_dict['Category']
|
||||||
|
|
||||||
|
if 'Answer' in attributes_dict.keys():
|
||||||
|
self.answer = attributes_dict['Answer']
|
||||||
|
else:
|
||||||
|
raise Exception("Cannot instantiate Question: 'Answer' attribute required.")
|
||||||
|
|
||||||
|
if 'Regexp' in attributes_dict.keys():
|
||||||
|
self.regexp = attributes_dict['Regexp']
|
||||||
|
|
||||||
|
if 'Author' in attributes_dict.keys():
|
||||||
|
self.category = attributes_dict['Author']
|
||||||
|
|
||||||
|
if 'Level' in attributes_dict.keys() and attributes_dict['Level'] in self.LEVELS:
|
||||||
|
self.level = attributes_dict['level']
|
||||||
|
|
||||||
|
if 'Comment' in attributes_dict.keys():
|
||||||
|
self.comment = attributes_dict['Comment']
|
||||||
|
|
||||||
|
if 'Score' in attributes_dict.keys():
|
||||||
|
self.score = attributes_dict['Score']
|
||||||
|
|
||||||
|
if 'Tip' in attributes_dict.keys():
|
||||||
|
self.tip = attributes_dict['Tip']
|
||||||
|
|
||||||
|
if 'Tipcycle' in attributes_dict.keys():
|
||||||
|
self.tipcycle = attributes_dict['Tipcycle']
|
||||||
|
|
||||||
|
|
||||||
|
class QuestionBank:
|
||||||
|
"""
|
||||||
|
Represents a MoxQuizz question bank.
|
||||||
|
"""
|
||||||
|
|
||||||
|
filename = ''
|
||||||
|
questions = list()
|
||||||
|
|
||||||
|
# Case sensitive, to remain backwards-compatible with MoxQuizz.
|
||||||
|
KEYS = ('Answer',
|
||||||
|
'Author',
|
||||||
|
'Category',
|
||||||
|
'Comment',
|
||||||
|
'Level',
|
||||||
|
'Question',
|
||||||
|
'Regexp',
|
||||||
|
'Score',
|
||||||
|
'Tip',
|
||||||
|
'Tipcycle',
|
||||||
|
)
|
||||||
|
|
||||||
|
def __init__(self, filename):
|
||||||
|
"""
|
||||||
|
Construct a question bank from a file.
|
||||||
|
"""
|
||||||
|
self.filename = filename
|
||||||
|
self.questions = self.parse(filename)
|
||||||
|
|
||||||
|
def parse(self, filename):
|
||||||
|
"""
|
||||||
|
Read a Moxquizz question bank file into a list.
|
||||||
|
"""
|
||||||
|
questions = list()
|
||||||
|
|
||||||
|
with open(filename) as f:
|
||||||
|
key = ''
|
||||||
|
i = 0
|
||||||
|
|
||||||
|
# new question
|
||||||
|
q = dict()
|
||||||
|
q['Tip'] = list()
|
||||||
|
|
||||||
|
for line in f:
|
||||||
|
line = line.strip()
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
# Ignore comments.
|
||||||
|
if line.startswith('#'):
|
||||||
|
continue
|
||||||
|
|
||||||
|
# A blank line starts a new question.
|
||||||
|
if line == '':
|
||||||
|
# Store the previous question, if valid.
|
||||||
|
if 'Question' in q.keys() and 'Answer' in q.keys():
|
||||||
|
question = Question(q)
|
||||||
|
questions.append(question)
|
||||||
|
|
||||||
|
# Start a new question.
|
||||||
|
q = dict()
|
||||||
|
q['Tip'] = list()
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Fetch the next parameter.
|
||||||
|
try:
|
||||||
|
(key, value) = line.split(':', 1)
|
||||||
|
except ValueError:
|
||||||
|
print("Unexpected weirdness in MoxQuizz questionbank '%s', line %s." % (self.filename, i))
|
||||||
|
continue
|
||||||
|
# break # TODO: is it appropriate to bail on broken bank files?
|
||||||
|
|
||||||
|
# Ignore bad parameters.
|
||||||
|
if key not in self.KEYS:
|
||||||
|
print("Unexpected key '%s' in MoxQuizz questionbank '%s', line %s." % (key, self.filename, i))
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Enumerate the Tips.
|
||||||
|
if key == 'Tip':
|
||||||
|
q['Tip'].append(value.strip())
|
||||||
|
else:
|
||||||
|
q[key] = value.strip()
|
||||||
|
|
||||||
|
return questions
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
qb = QuestionBank('/home/johnno/questions.doctorlard.en')
|
||||||
|
for q in qb.questions:
|
||||||
|
print(q.question)
|
||||||
|
a = input('A: ')
|
||||||
|
if a.lower() == q.answer.lower():
|
||||||
|
print("Correct!")
|
||||||
|
else:
|
||||||
|
print("Incorrect - the answer is '%s'" % q.answer)
|
||||||
Loading…
Add table
Reference in a new issue