82 lines
3.7 KiB
YAML
82 lines
3.7 KiB
YAML
---
|
|
metadata:
|
|
display_name: Custom Python-Evaluated Input
|
|
markdown: !!null
|
|
data: |
|
|
<problem>
|
|
<p>
|
|
In custom Python-evaluated input (also called "write-your-own-grader"
|
|
problems), the grader uses a Python script that you create and embed in
|
|
the problem to evaluate a learner's response or provide hints. These
|
|
problems can be any type. Numerical input and text input problems are
|
|
the most common write-your-own-grader problems.
|
|
</p>
|
|
<p>
|
|
You can use script tag format or answer tag format to create these problems.
|
|
</p>
|
|
<p>
|
|
You can create custom Python-evaluated input problems that provide
|
|
partial credit or that randomize variables in the Python code. You can
|
|
also add images to the solution by using an HTML "img" tag. Note that
|
|
the "img" tag must be between the "div" tags that are inside the
|
|
"solution" tags, and that learners do not see these images until they
|
|
click the "Show Answer" button.
|
|
</p>
|
|
<p>
|
|
For more information, see <a href="https://docs.openedx.org/en/latest/educators/references/course_development/exercise_tools/guide_custom_python_problem.html" target="_blank">
|
|
Write-Your-Own-Grader Problem</a> in <i>Building and Running an Open edX Course</i>.
|
|
</p>
|
|
<p>
|
|
When you add the problem, be sure to select <strong>Settings</strong>
|
|
to specify a <strong>Display Name</strong> and other values that apply.
|
|
</p>
|
|
<p>You can use the following example problem as a model.</p>
|
|
<hr/>
|
|
|
|
<customresponse cfn="test_add_to_ten">
|
|
<script type="loncapa/python">
|
|
|
|
def test_add_to_ten(expect, ans):
|
|
return test_add(10, ans)
|
|
|
|
</script>
|
|
<label>Enter two integers that sum to 10.</label>
|
|
<textline size="40" correct_answer="3" label="Enter first number" /><br/>
|
|
<textline size="40" correct_answer="7" label="Enter second number" />
|
|
<solution>
|
|
<div class="detailed-solution">
|
|
<p>Explanation</p>
|
|
<p>Any set of integers on the line \(y = 10 - x\) satisfy these constraints.</p>
|
|
</div>
|
|
</solution>
|
|
</customresponse>
|
|
|
|
<customresponse cfn="test_add" expect="20">
|
|
<script type="loncapa/python">
|
|
|
|
def test_add(expect, ans):
|
|
try:
|
|
a1=int(ans[0])
|
|
a2=int(ans[1])
|
|
return (a1+a2) == int(expect)
|
|
except ValueError:
|
|
return False
|
|
|
|
</script>
|
|
<label>Enter two integers that sum to 20.</label>
|
|
<textline size="40" correct_answer="11" label="Enter first number" /><br/>
|
|
<textline size="40" correct_answer="9" label="Enter second number" />
|
|
<solution>
|
|
<div class="detailed-solution">
|
|
<p>Explanation</p>
|
|
<p>Any set of integers on the line \(y = 20 - x\) satisfy these constraints.</p>
|
|
<p>To add an image to the solution, use an HTML "img" tag. Make sure to include alt text.</p>
|
|
<img src="/static/images/placeholder-image.png" width="400"
|
|
alt="Description of image, with a primary goal of explaining its
|
|
relevance to the problem or concept being illustrated for someone
|
|
who is unable to see the image."/>
|
|
</div>
|
|
</solution>
|
|
</customresponse>
|
|
</problem>
|