#################################### CustomResponse XML and Python Script #################################### This document explains how to write a CustomResponse problem. CustomResponse problems execute Python script to check student answers and provide hints. There are two general ways to create a CustomResponse problem: ***************** Answer tag format ***************** One format puts the Python code in an ```` tag: .. code-block:: xml

What is the sum of 2 and 3?

# Python script goes here
The Python script interacts with these variables in the global context: * ``answers``: An ordered list of answers the student provided. For example, if the student answered ``6``, then ``answers[0]`` would equal ``6``. * ``expect``: The value of the ``expect`` attribute of ```` (if provided). * ``correct``: An ordered list of strings indicating whether the student answered the question correctly. Valid values are ``"correct"``, ``"incorrect"``, and ``"unknown"``. You can set these values in the script. * ``messages``: An ordered list of message strings that will be displayed beneath each input. You can use this to provide hints to users. For example ``messages[0] = "The capital of California is Sacramento"`` would display that message beneath the first input of the response. * ``overall_message``: A string that will be displayed beneath the entire problem. You can use this to provide a hint that applies to the entire problem rather than a particular input. Example of a checking script: .. code-block:: python if answers[0] == expect: correct[0] = 'correct' overall_message = 'Good job!' else: correct[0] = 'incorrect' messages[0] = 'This answer is incorrect' overall_message = 'Please try again' **Important**: Python is picky about indentation. Within the ```` tag, you must begin your script with no indentation. ***************** Script tag format ***************** The other way to create a CustomResponse is to put a "checking function" in a `` **Important**: Python is picky about indentation. Within the ``