<div dir="ltr">Hi Josh,<div><br></div><div>The easy solution is to move this calculation to the <part> that requires it.  You are allowed multiple <script> blocks inside a problem.  So you can split up the single <script> block that occurs at the top of your problem into several different <script> blocks belonging to each <part>.   </div>

<div><br></div><div>Then, since you use "Show Parts One-at-a-Time" the <script> of each part shouldn't be evaluated until the &submission() values from the previous <part> have been entered.</div>

<div><br></div><div>Todd</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Sep 2, 2013 at 1:03 PM, Josh Wolosz <span dir="ltr"><<a href="mailto:jwolosz@slrsd.org" target="_blank">jwolosz@slrsd.org</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div><div><div><div>Hi Everyone,<br><br>I have a question in regards to Custom Response problems.  I 
would like to try moving some of my labs into lon-capa, and one of the 
first ones involves working with percent error (for high school freshman).<br>
<br></div>Here's what I would like to have happen:<br><br></div>1) Students enter an estimated value<br></div>2) Students enter the actual/measured value<br></div>3) Students then input their percent error which loncapa calculates and determines if they are correct or not<br>



<br></div>Here is the script I have tried:<br><br><b><script type="loncapa/perl"><br># Get the entered answer. First argument is partID, second is responseID<br>$given=&submission(1,11);<br>$example='You chose '.$given.' m';<br>



$given2=&submission(3,4);<br>$example2='You chose '.$given2.' m';<br>$a=&abs($given2-$given)/$given2;<br></script></b><br><br></div>I'm getting an error returned saying there is an illegal division by zero, specifically:<br>



<br><b>$a=&abs($given2-$given)/$given2;<br><br></b></div>I 
understand that at the beginning of the problem nothing has been 
submitted, so $given2 has no value.  Is there a way around this?  
Thanks for your help, and I apologize if it is a very simple solution 
that I am missing.<br>
<br></div><div>Sincerely<br></div><div>Joshua Wolosz<br><br></div><div>The full code is:<br><br><problem><br><br>    <parameter name="ordered" id="13" type="string_yesno" default="no" description="Show Parts One-at-a-Time" /><br>



<br><script type="loncapa/perl"><br># Get the entered answer. First argument is partID, second is responseID<br>$given=&submission(1,11);<br>$example='You chose '.$given.' m';<br>$given2=&submission(3,4);<br>



$example2='You chose '.$given2.' m';<br></div><div>$a1=100*&abs($given2-$given)/$given2;<br></div></script><br><br><part id="1"><br><startouttext /><br><i><b>Note:</b>
 You do not need to include the units when you input your 
calculations.</i><br></br><br>
<br>What did you estimate the width of the object to be?<br><endouttext /><br><customresponse answerdisplay="$example" id="11"><br>    <answer type="loncapa/perl"># We do not want a vector<br>



if ($submission=~/\,/) { return 'EXTRA_ANSWER'; }<br># No units needed<br>if ($submission=~/^\d+\s+\w+$/) { return 'UNIT_NOTNEEDED'; }<br># Need a numerical answer here<br>if ($submission!~/^[\d\.]+$/) { return 'WANTED_NUMERIC'; }<br>



{ return 'EXACT_ANS'; }</answer><br>    <textline readonly="no" /><br></customresponse><startouttext />meters<endouttext /><br></part><br><br><part id="3"><br>



<startouttext /><br>What did you <u>measure</u> the width of the object to be?  <br><endouttext /><br><customresponse answerdisplay="$example2" id="4"><br>    <answer type="loncapa/perl"># We do not want a vector<br>



if ($submission=~/\,/) { return 'EXTRA_ANSWER'; }<br># No units needed<br>if ($submission=~/^\d+\s+\w+$/) { return 'UNIT_NOTNEEDED'; }<br># Need a numerical answer here<br>if ($submission!~/^[\d\.]+$/) { return 'WANTED_NUMERIC'; }<br>



{ return 'EXACT_ANS'; }</answer><br>    <textline readonly="no" /><br></customresponse><startouttext />meters<endouttext /><br></part><br><br><part id="5"><br>



<startouttext /><br>What was your percent error for the width?<br><endouttext /><br><numericalresponse answer="$a1" id="194"><br><responseparam name="tol" type="tolerance" default="0.5%" description="Numerical Tolerance" /><br>



    <textline readonly="no" /><br></numericalresponse><br></part><br></problem</div>

<br>
<p></p><p style></p><hr><p></p><p style><font>When writing or responding, please remember that the Secretary of the Commonwealth of Massachusetts has determined that email is a public record.</font></p><p style><font>This communication may contain privileged or other confidential information. If you are not the intended recipient, or believe that you have received this communication in error, please do not print, copy, retransmit, disseminate, or otherwise use the information. Also, please indicate to the sender that you have received this email in error, and delete the copy you received.  Thank you for your cooperation.</font></p>

<p></p><br>_______________________________________________<br>
LON-CAPA-users mailing list<br>
<a href="mailto:LON-CAPA-users@mail.lon-capa.org">LON-CAPA-users@mail.lon-capa.org</a><br>
<a href="http://mail.lon-capa.org/mailman/listinfo/lon-capa-users" target="_blank">http://mail.lon-capa.org/mailman/listinfo/lon-capa-users</a><br>
<br></blockquote></div><br></div>