Closed jolyonb closed 6 years ago
With this fix, the following code works in edX!!!
<problem>
<script type="loncapa/python">
from mitxgraders import *
</script>
<customresponse cfn="FormulaGrader(variables=['x'])" answer="2*x" >
<textline math="true" />
</customresponse>
</problem>
Putting primes in variable names is a bit annoying, alas - you need to do XML escaping. However, for simple things, this is beautiful!
Time to do some large scale restructuring of the documentation, I guess...
This is cool!
Re:
Time to do some large scale restructuring of the documentation, I guess...
It probably boils down to personal preference... I think that if I were writing a large number of problems, I would try to use essentially the same customresponse tag for all problems, and have the tag attributes reference python variables $grader
and $expect
. Something like:
<problem>
<script type="loncapa/python">
from mitxgraders import *
expect = 'x^2'
grader = FormulaGrader(answers=expect, variables=['x'])
</script>
<customresponse cfn="$grader" expect="$expect">
<textline math="true" />
</customresponse>
</problem>
If you decided to do this, we could even expose grader.config['answers'][0]['expect']
as grader.expect
(if it exists and is unique, or expose the single answer with 'ok': True
).
I'm more thinking about writing a script to translate old problems to use our library, at least for the improved JS preprocessing and the improved error message. Being able to inline things makes that much easier!
So, it turns out that edX sends us a unicode version of the expect string, not a string version. This fixes the appropriate pieces and makes everything work on edX :-)