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

Gerd Kortemeyer korte at lite.msu.edu
Thu May 24 18:33:22 EDT 2012


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>



More information about the LON-CAPA-users mailing list