Quiz Plugin

Picture of Charlie Daly
Quiz Plugin

Hello, I've created a (very rough) plugin but the idea is to allow course creators to easily create individual questions for students. I've documented the main ideas at 

This video is circa 13 minutes but can be watched at double speed for the super rushed.

If anybody is interested  I would be delighted to pass on the code. Well, not so delighted about the PHP code which is a very ugly hack but I am hoping that someone will make it prettier.

Although the video demonstrates arithmetic questions, very sophisticated questions can be generated which are still individual to each student.

I have another video which shows some of these more sophisticated questions and that video is here: 

Average of ratings: -
Tim at Lone Pine Koala Sanctuary
Re: Quiz Plugin
Core developersDocumentation writersParticularly helpful MoodlersPlugin developers

You might catch more interested people if you post in the Quiz forum: https://moodle.org/mod/forum/view.php?id=737

Also, I am not watching a 13-minute video, at least not now (any chance of a few paragraphs and screen grabs?) but I wonder if there is any overlap with https://moodle.org/mod/forum/discuss.php?d=373329.

Average of ratings: -
Picture of Charlie Daly
Re: Quiz Plugin

> any chance of a few paragraphs and screen grabs?

Sure. Recently there was a query about generating questions with randomized parameters and they specifically mentioned Caesar's cipher. So, before breakfast I created such a question. The following screen shots will show two different students interacting with the question.

First, s1 views the question:

On another computer, s2 selects the same problem, but he is given a different plaintext and key:

s2 submits his solution and is marked.

There is nothing super remarkable about this, except that you don't need to program in PHP. You can choose any language that can use CGI.

The code to create this question is quite straightforward (assuming you are comfortable with Python):

# This will define the question (choose a plaintext and a key)
def gen_vals(seed):

      plaintexts = [
         'semper fidelis',
         'attack at dawn',
         'top secret',
         'keep your tongue',

      # Choose one plaintext for the question
      plaintext = plaintexts[random.randint(0, len(plaintexts) - 1)]
      # Now, choose a key
      key = random.randint(1, 25)
      return [key, plaintext]

This is then used by the function to generate a specification:

def gen_spec(rand_vals):
   key, plaintext = rand_vals
   return "Perform a Caesar cypher on the plaintext '{}' using the key {:d} and enter the result in the box below.".format(plaintext, key)

and by the function to generate the correct answer:

def gen_answer(rand_vals):
   key, plaintext = rand_vals
   return caesar(key, plaintext)

but the best thing is that the marking function can provide very specific feedback:

# Mark the response
def gen_mark(rand_vals, response):
   if response == gen_answer(rand_vals):
      return "1\nWell done, {} is the correct answer".format(response)
   elif response.lower() == gen_answer(rand_vals).lower():
      return "0.5\nYour solution is correct except for the case of the letters."
      # Provide some feedback on an incorrect answer.
      if len(response) != len(gen_answer(rand_vals)):
         return "0\n{} is not correct.\n There should be {:d} characters in your response".format(response, len(gen_answer(rand_vals)))
         # Check if they encrypted using an incorrect key
         key, plaintext = rand_vals
         student_key = ord(response[0]) - ord(plaintext[0]) # work out the shift for the first letter
         if caesar(student_key, plaintext) == response:
            return "0.25\nYou correctly encrypted the plaintext, but you used the wrong key ({:d})".format(student_key)
            return "0\n{} is not correct".format(response)

This function first checks if the answer is correct, in which case, the response is worth full marks (1), otherwise, it checks that the case matches, in which case, the mark will be 0.5.

Next, it checks the length is OK, which can help the student spot errors. Finally, it checks if the student encrypted with the wrong key and, in this case, the student is awarded 25% of the marks.

If you use this question in a lab, you will soon discover what the most common misconceptions are and you can tailor the mark function to provide specific feedback for that misconception.

Naturally, you will need to be a programmer to write this code, but you only need to write four shortish functions in a language of your choice.

To add this question to a quiz, first on the moodle end, you will have to add this plugin type to your quiz and give it an appropriate name and category. That's it. On the Python end, you need to place your code in the appropriate directory (based on the question name and category). You also need to ensure that cgi is enabled on your web server.

Sorry this post is so long. I have not the skill to shorten it.

PS thanks for your tip on the quiz forum. I don't think the plugin ready for primetime yet. I don't understand enough of Moodle code to ensure that I'm not breaking something. If noone else is interested, I'll use it this year and then I can see about releasing it when I'm more confident.

PPS I am very pleased to see your new plugin allowing use of question outside the quiz environment.

Average of ratings: Useful (1)
Picture of Marcus Green
Re: Quiz Plugin
Core developersParticularly helpful MoodlersPlugin developersTesters

Sounds intriguing. Could you put the source on Github (or equivalent). I got some really helpful code contributed to one of my question types recently via Github.

Average of ratings: -
Mary Cooch
Re: Quiz Plugin
Documentation writersMoodle Course Creator Certificate holdersMoodle HQParticularly helpful MoodlersTestersTranslators

Moving this to the Quiz forum as suggested by Tim...

Average of ratings: -
Picture of Charlie Daly
Re: Quiz Plugin

Thanks Marcus,

I put the code + installation note here: http://www.computing.dcu.ie/~cdaly/qtype_plugin.zip

I may lookup github later.


Average of ratings: Useful (1)
Picture of Charlie Daly
Re: Quiz Plugin
Average of ratings: Useful (1)