[LON-CAPA-users] Any way to do this???

Mills, Douglas G dmills at illinois.edu
Fri May 25 11:26:47 EDT 2012


I'm assuming that there is one return value for all inputs since they're all
part of one response -- is that correct?  Or is there also an array for that
as well?  I'm guessing though that once your code hits a return condition it
matches, it returns that message and exits, right?  Previously I'd been
providing some customized feedback per input based on the individual return
codes since they were all separate responses. I can work around this but
just wanted to check my assumption that there is only one return code for
all the inputs in the response together, right?

Thanks!


On 5/24/12 5:33 PM, "Gerd Kortemeyer" <korte at lite.msu.edu> wrote:

> Hi,
> 
> On May 24, 2012, at 6:21 PM, Gerd Kortemeyer wrote:
> 
>>> 
>> 
>> In this case, &submission returns a pointer to the array:
>> 
>> $data=&submission(partid,responseid);
>> $entry=$$data[0];
> 
> The problem that I had already sent a part of actually does this. I'll just
> send the whole thing.
> 
> - Gerd.
> 
> <problem>
>     <parameter name="ordered" id="11" type="string_yesno" default="yes"
> description="Show Parts One-at-a-Time" />
> 
> <script type="loncapa/perl">
> #Enter the computations here
> $sum=0;
> $sumq=0;
> $ave=0;
> $stdev=0;
> if (&check_status('data')) {
>    $submission=&submission('data','mydata');
>    for ($i=0;$i<=5;$i++) {
>       $height[$i]=$$submission[2*$i];
>       $time[$i]=$$submission[2*$i+1];
>       if ($time[$i]) {
>          $speed[$i]=$height[$i]/$time[$i];
>          $sum+=$speed[$i];
>       }
>    }
>    $ave=$sum/6.;
>    for ($i=0;$i<=5;$i++) {
>        $sumq+=($speed[$i]-$ave)**2;
>    }
>    $stdev=sqrt($sumq/6);
> } else {
>    for ($i=0;$i<=5;$i++) {
>       $height[$i]='';
>       $time[$i]='';
>    }
> }
> </script>
>     <img alt="Walking in Switzerland" align="right" src="walking.jpg"
> encrypturl="no" />
> 
> <startouttext />
> <h1>Walking</h1>
> <p>Let's determine your average walking speed.
> </p>
> <endouttext />
> <part id="data">
> <startouttext /><p>Find yourself a large area away from traffic, potholes and
> black holes, and try to determine your average walking speed
> (distance/time).</p><endouttext />
> <customresponse id="mydata">
>     <answer type="loncapa/perl">for ($i=0;$i<=5;$i++) {
>     $height[$i]=$$submission[2*$i];
>     unless ($height[$i]) { return 'MISSING_ANSWER'; }
>     unless ($height[$i]=~/^[\d\.]+$/) { return 'WANTED_NUMERIC'; }
>     $time[$i]=$$submission[2*$i+1];
>     unless ($time[$i]) { return 'MISSING_ANSWER'; }
>     unless ($time[$i]=~/^[\d\.]+$/) { return 'WANTED_NUMERIC'; }
> }
> for ($i=0;$i<=5;$i++) {
>     if ($height[$i]/$time[$i]>3) { return 'INCORRECT'; }
> }
> return 'APPROX_ANS';</answer>
> <startouttext /><table><tr><th>Distance [Meters]</th><th>Time
> [Seconds]</th></tr><endouttext />
> <startouttext /><tr><td><endouttext /><textline readonly="no" /><startouttext
> />$height[0]</td><td><endouttext /><textline readonly="no" /><startouttext
> />$time[0]</td></tr><endouttext />
> <startouttext /><tr><td><endouttext /><textline readonly="no" /><startouttext
> />$height[1]</td><td><endouttext /><textline readonly="no" /><startouttext
> />$time[1]</td></tr><endouttext />
> <startouttext /><tr><td><endouttext /><textline readonly="no" /><startouttext
> />$height[2]</td><td><endouttext /><textline readonly="no" /><startouttext
> />$time[2]</td></tr><endouttext />
> <startouttext /><tr><td><endouttext /><textline readonly="no" /><startouttext
> />$height[3]</td><td><endouttext /><textline readonly="no" /><startouttext
> />$time[3]</td></tr><endouttext />
> <startouttext /><tr><td><endouttext /><textline readonly="no" /><startouttext
> />$height[4]</td><td><endouttext /><textline readonly="no" /><startouttext
> />$time[4]</td></tr><endouttext />
> <startouttext /><tr><td><endouttext /><textline readonly="no" /><startouttext
> />$height[5]</td><td><endouttext /><textline readonly="no" /><startouttext
> />$time[5]</td></tr><endouttext />
> <startouttext /></table><endouttext />
>     
> </customresponse>
> 
> </part>
> <part id="12">
> <startouttext />What is your average walking speed?<endouttext />
> <numericalresponse unit="m/s" format="2s" answer="$ave" id="13">
>     <responseparam name="tol" type="tolerance" default="10%"
> description="Numerical Tolerance" />
> <textline readonly="no" />
> </numericalresponse>
> </part>
> <part id="14">
> <startouttext />What is the standard deviation of your walking
> speed?<endouttext />
> <numericalresponse unit="m/s" format="2s" answer="$stdev" id="15">
>     <responseparam name="tol" type="tolerance" default="10%"
> description="Numerical Tolerance" />
> <textline readonly="no" />
> </numericalresponse>
> </part>
> <allow src="/res/msu/kortemey/physicsprecourse/modelexp/walking.jpg" />
> </problem>
> 
> _______________________________________________
> LON-CAPA-users mailing list
> LON-CAPA-users at mail.lon-capa.org
> http://mail.lon-capa.org/mailman/listinfo/lon-capa-users


Doug

Douglas Mills
Director of Instructional Technologies
Department of Chemistry
University of Illinois
dmills at illinois.edu
(217) 244-5739 




More information about the LON-CAPA-users mailing list