Skip to content

Python library to populate Moodle question banks using a Cloze/XML format

License

Notifications You must be signed in to change notification settings

miguelinux314/moocloze

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

moocloze

Python library to populate Moodle question banks using a Cloze/XML format.

It aims to provide a functionality similar to that of PyCloze, but reducing the necessity of specific knowledge about the Moodle XML or Cloze formats.

Contents:

Installation

The moocloze library is available as a pip package:

pip install moocloze

You can then import it as a normal package in any python code:

import moocloze

Minimal example

The following code (download source)

import moocloze

questions = [moocloze.Question(
    name=f"How much is {i}+{i}",
    contents=f"What is the result of {i}+{i}? "
             f"{moocloze.Numerical(i + i)}")
    for i in range(3)]

moocloze.questions_to_xml_file(questions=questions, output_path="example_quiz.xml")

generates a file in Cloze/XML format (download XML file) that can be imported in Moodle. Once imported, 3 questions are added to the bank, one of which is shown next:

Example output of a numerical question

Creating questions and importing into Moodle

The following workflow is proposed to add questions to a Moodle category

  • In your computer:

    1. Create a list of (related) Question instances.
      import moocloze
      questions = [moocloze.Question(name="...", contents="..."), ...]
    2. Export the set of questions into an .xml file with Moodle XML/Cloze format
      moocloze.questions_to_xml_file(questions=questions, output_path="my_questions.xml")
  • In your Moodle course, import the questions:

    1. Go to your course's Question bank

      question bank

    2. (Optional) Go to the question Categories page and add your category

      categories

    3. Go to the question Import page, select the category where questions are to be imported (here "Raw audio file size", shown under the "General" section), upload your xml file (e.g., "my_questions.xml" in the example below) and press "Import":

      import

    4. You will be shown a confirmation page. If no errors are found, your generated questions are now read to be used!

    5. If you don't have one, create a Quiz activity. Go to its Questions tab, and add them as desired. Moodle allows showing random questions from a given category. You can use it to your advantage to have each student use a randomized variation of a problem, e.g., with different numeric values.

Full example with all field types

You can find a complete example that produces a single question using all supported field (response) types:

  • moocloze.Numerical (integers or floats, with arbitrary error tolerance)
  • moocloze.Multiresponse (one or more valid options using checkboxes)
  • moocloze.Multichoice (one valid option among several, using dropdown menus or radio buttons)
  • moocloze.ShortAnswer (short text)

A screenshot of the question is shown next (see full size):

Adding feedback to the questions

Whenever you instantiate the moocloze.Question, you can pass a general_feedback parameter to it, as in:

import moocloze

question = moocloze.Question(
    name=f"Simple question",
    contents=f"How many sides does a dodecahedron have?"
             f"{moocloze.Numerical(answer=12, show_tolerance=False)}",
    general_feedback="Do not confuse it with the icosahedron (20 faces).")

import

References

About

Python library to populate Moodle question banks using a Cloze/XML format

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages