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, 6 months ago) by www
Branches: MAIN
CVS tags: HEAD
More comprehensive example for <externalresponse>

    1: <problem>
    2: <script type="loncapa/perl">
    3: sub fact {
    4:    my $n=shift;
    5:    if ($n==1) {
    6:       return $n;
    7:    } else {
    8:       return $n*&fact($n-1);
    9:    }
   10: }
   11: 
   12: $testvalues='0=1';
   13: foreach $i (1..3) {
   14:    $rand=&random(3,8,1);
   15:    $testvalues.=','.$rand.'='.&fact($rand);
   16: }
   17: 
   18: %args=('somecode' => (<<'ENDCODE')
   19: sub negative {
   20:    my ($number)=@_;
   21:    return $number<0;
   22: }
   23: ENDCODE
   24: );
   25: 
   26: 
   27: </script>
   28: 
   29: 
   30: <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
   31: boolean function <tt>&amp;negative(number)</tt>, which returns <tt>true</tt> if the argument is negative.
   32: <instructorcomment>
   33: Sample code for an evaluation script can be found <a href="/res/adm/includes/templates/sampleexternal.pl">here.</a></instructorcomment>
   34: <endouttext />
   35: <externalresponse url="http://localhost/cgi-bin/sampleexternal.pl" answer="$testvalues" form="%args" answerdisplay="The most elegant (and dangerous) solution is recursive.">
   36: <textfield />
   37: 
   38: </externalresponse>
   39: </problem>

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