File:  [LON-CAPA] / loncom / homework / templates / sampleexternal.problem
Revision 1.4: download - view: text, annotated - select for diffs
Sat Feb 4 15:12:40 2012 UTC (12 years, 3 months ago) by www
Branches: MAIN
CVS tags: HEAD
More comprehensive example for <externalresponse>

<problem>
<script type="loncapa/perl">
sub fact {
   my $n=shift;
   if ($n==1) {
      return $n;
   } else {
      return $n*&fact($n-1);
   }
}

$testvalues='0=1';
foreach $i (1..3) {
   $rand=&random(3,8,1);
   $testvalues.=','.$rand.'='.&fact($rand);
}

%args=('somecode' => (<<'ENDCODE')
sub negative {
   my ($number)=@_;
   return $number<0;
}
ENDCODE
);


</script>


<startouttext />Write a Perl subroutine called <tt>factorial</tt>, which returns the factorial of its argument, e.g. <tt>&amp;factorial(17)=17!</tt>. You can use the
boolean function <tt>&amp;negative(number)</tt>, which returns <tt>true</tt> if the argument is negative.
<instructorcomment>
Sample code for an evaluation script can be found <a href="/res/adm/includes/templates/sampleexternal.pl">here.</a></instructorcomment>
<endouttext />
<externalresponse url="http://localhost/cgi-bin/sampleexternal.pl" answer="$testvalues" form="%args" answerdisplay="The most elegant (and dangerous) solution is recursive.">
<textfield />

</externalresponse>
</problem>

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>