[LON-CAPA-users] new adaptive hint format

Guy Albertelli II lon-capa-users@mail.lon-capa.org
Wed, 1 Aug 2007 15:45:08 -0400


Hi Robley,

> The new "Adative Hint" examples allow you to provide a "wrong" answer that
> triggers a hint, but using that format how do you trigger a hint where the
> answer is in some kind of range (i.e. positive when it should be negative,
> as here.)  I suppose for a simpler "range", you could put a value in with a
> tolerance that covers the range, but is there some way to be more specific
> (i.e. when $answer <100 & >95).

I suggest using tolerance and <numericalhint>

Or you could use <customhint> if you wnat to do something more
extravagent

Examples:

1) uses <numericalhint> and tolerance to give different hints, if the
   number entered is within .5 of $a - $b gives 1 hint, gives a different
   hint on any other response


<problem>
  <script type="loncapa/perl">
$a=&random(1,10,1);
$b=&random(1,10,1);
$c=$a+$b;
$sub=$a-$b;
  </script>
  
  <startouttext />What is $a + $b?<endouttext />
  
  <numericalresponse answer="$c">

    <responseparam type="tolerance" default="5%" name="tol"
                   description="Numerical Tolerance" />

    <textline readonly="no" />

    <hintgroup showoncorrect="no">
      <numericalhint answer="$sub" name="subtraction">
        <responseparam name="tol" type="tolerance" default="0.5"
                       description="Numerical Tolerance" />
      </numericalhint>
      <hintpart on="subtraction">
        <startouttext />You have subtracted the numbers<endouttext />
      </hintpart>
      <hintpart on="default">
        <startouttext />Hmm, that doesn't look right to me.<endouttext />
      </hintpart>
    </hintgroup>

  </numericalresponse>
</problem>



2) This one uses a custom hint to detect any negative numbers and give
one hint, and a numericalhint to detect when they multiplied, and finaly a 3rd hint by default


<problem>
  <script type="loncapa/perl">
$a=&random(1,10,1);
$b=&random(1,10,1);
$c=$a+$b;
$mul=$a*$b;
  </script>
  
  <startouttext />What is $a + $b?<endouttext />
  
  <numericalresponse answer="$c">

    <responseparam type="tolerance" default="5%" name="tol" description="Numerical Tolerance" />

    <textline readonly="no" />

    <hintgroup showoncorrect="no">
      <customhint name="negative">
        <answer type="loncapa/perl">

if ($submission =~ /[\d\.\-]/ && $submission < 0) {
   return 'APPROX_ANS';
}
return 'INCORRECT';
        </answer>
      </customhint>

      <numericalhint answer="$mul" name="multiply">
        <responseparam name="tol" type="tolerance" default="0.5" description="Numerical Tolerance" />
      </numericalhint>
      
      <hintpart on="negative">
        <startouttext />Hmm, seems unlikely that addition of two positive numbers would be negative.<endouttext />
      </hintpart>

      <hintpart on="multiply">
        <startouttext />While multiplication is repeated addition, I think you should rethink your use of it here.<endouttext />
      </hintpart>
        
      <hintpart on="default">
        <startouttext />Hmm, that doesn't look right to me.<endouttext />
      </hintpart>
    </hintgroup>

  </numericalresponse>
</problem>

-- 
guy@albertelli.com   0-7-0-9-27,137