From c3da73ed1eea6be8afb24d5505190b2d4fa65ce9 Mon Sep 17 00:00:00 2001 From: Will Daly Date: Fri, 1 Mar 2013 10:57:57 -0500 Subject: [PATCH] Changed title of custom response doc. Added custom response doc to index --- .../course_data_formats/custom_response.rst | 142 ++++++++++++++++++ doc/public/index.rst | 1 + 2 files changed, 143 insertions(+) create mode 100644 doc/public/course_data_formats/custom_response.rst diff --git a/doc/public/course_data_formats/custom_response.rst b/doc/public/course_data_formats/custom_response.rst new file mode 100644 index 0000000000..1ca8214915 --- /dev/null +++ b/doc/public/course_data_formats/custom_response.rst @@ -0,0 +1,142 @@ +#################################### +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 ``