File:  [LON-CAPA] / loncom / homework / templates / sampleexternal.problem
Revision 1.2: download - view: text, annotated - select for diffs
Mon Dec 20 19:18:14 2010 UTC (13 years, 4 months ago) by www
Branches: MAIN
CVS tags: HEAD
Somewhat better Perl :-(

<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);
}
</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>.
<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">
<textfield />

</externalresponse>
</problem>

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