Generating Moodle Question Banks using Python and Sympy

Python
Sympy
Teaching
Moodle
Published

February 9, 2023

Over the years I have developed some scripts for generating banks of questions for Moodle so that students can challenge themselves and check their answers. Sometimes I have been dealing with hundreds of students so an automated procedure is needed.

After checking with colleagues from my department at UPC and many hours of trial and error, I finally ended with the following solution, which works for GNU/Linux systems (although I guess that also works for other systems).

Requirements

The process needs the following components:

Steps

  1. Update ‘sample-quiz-generator.py’ to tailor your wishes.

  2. Execute this file using Python, for instance, in bash,

     python ./sample-quiz-generator.py

This will generate a TeX file ‘chunks-moodle.tex’ which contains the different questions and is included within the main file ‘template-python-moodle.tex’

  1. Run LuaLaTex to compile the file:

     lualatex template-python-moodle.tex
  2. This will create a PDF with solutions to preview and an XML to upload to Moodle.

  3. Upload the XML file to the platform of your choice.