---
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="http://edx.readthedocs.org/projects/edx-partner-course-staff/en/latest/exercises_tools/custom_python.html" target="_blank">
      Write-Your-Own-Grader Problem</a> in <i>Building and Running an 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>
      <p>______________________________________________________________________________</p>

      <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

      def test_add_to_ten(expect, ans):
          return test_add(10, ans)

      </script>
        <p>Enter two integers that sum to 10.</p>
        <customresponse cfn="test_add_to_ten">
          <textline size="40" correct_answer="3" label="Integer #1"/><br/>
          <textline size="40" correct_answer="7" label="Integer #2"/>
        </customresponse>
        <p>Enter two integers that sum to 20.</p>
        <customresponse cfn="test_add" expect="20">
          <textline size="40" correct_answer="11" label="Integer #1"/><br/>
          <textline size="40" correct_answer="9" label="Integer #2"/>
        </customresponse>
      <solution>
        <div class="detailed-solution">
          <p>Explanation</p>
          <p>Any set of integers on the line \(y = 10 - x\) and \(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>
      </problem>
