WeBWorK Problems

Too many answer blanks

Too many answer blanks

by Eric Stroyan -
Number of replies: 2
I was recently reviewing old chemistry problems (schedule change, teaching chem again) that I recalled worked correctly the last time I used them (2011).
The issue is that when a student selects the problem they get the error

"PG question processing error messages

PG warning messages


------
No answer blank provided for answer evaluator AnSwEr0003

------
Answer evaluator AnSwEr0003 was not executed due to errors.
========"

I have pasted the offending code below. I just don't see where the issue is. Any help would be appreciated.

Code:
##DESCRIPTION
#
#number of ions in ionic compound
#
##ENDDESCRIPTION
DOCUMENT();
loadMacros(
"PG.pl",
"PGbasicmacros.pl",
"PGchoicemacros.pl",
"PGanswermacros.pl",
"PGauxiliaryFunctions.pl",
);
#
#identify number of ions in a formula
#
TEXT(&beginproblem);
#
#Below is a portion of the macro normally stored in the macros directory
# usually loaded in loadMacros as ionic_compounds_ammonium.pl
#
%compounds=(
1=>{name=>"Ammonium Acetate",
formula=>"NH_{4}C_{2}H_{3}O_{2}",
ions=>[{ion=>"NH_{4}^{+}", name=>"ammonium", count=>1},
{ion=>"C_{2}H_{3}O_{2}^{-}", name=>"acetate", count=>1}],
composition=>[
 {atom=>7, count=>1},
 {atom=>1, count=>7},
 {atom=>6, count=>2},
 {atom=>8, count=>2},]},
2=>{name=>"Ammonium Bromate",
formula=>"NH_{4}BrO_{3}",
ions=>[{ion=>"NH_{4}^{+}", name=>"ammonium", count=>1},
{ion=>"BrO_{3}^{-}", name=>"bromate", count=>1}],
composition=>[
 {atom=>7, count=>1},
 {atom=>1, count=>4},
 {atom=>35, count=>1},
 {atom=>8, count=>3},]},
3=>{name=>"Ammonium carbonate",
formula=>"(NH_{4})_{2}CO_{3}",
ions=>[{ion=>"NH_{4}^{+}", name=>"ammonium", count=>2},
  {ion=>"CO_{3}^{2-}", name=>"carbonate", count=>1}],
composition=>[
 {atom=>7, count=>2},
 {atom=>1, count=>8},
 {atom=>6, count=>1},
 {atom=>8, count=>3},]},
);
#
# get information on one of the compounds
#
$count=keys %compounds;
@items=(1..$count);
$S = list_random(@items);
$name = $compounds{$S}{name};
$form = $compounds{$S}{formula};
$i=0.;
for $who (@{$compounds{$S}{ions}})
 {$n=$i;
  $ion_at[$i]=$who->{ion};
  $name_ion[$i]=$who->{name};
  $N_ion[$i] = $who->{count};
  $i=$i+1;
  }
$i=0;
#
BEGIN_TEXT
Enter the correct number of each ion listed for \($form\).$BR
END_TEXT
#
# Generate answer blanks
#
for ($i=0;$i<=$n;$i++)
{
BEGIN_TEXT
Number of $name_ion[$i] ions = \{ans_rule(5)\}. $BR
END_TEXT
}
#
# Set up correct answers
#
$i=0;
for ($i=0;$i<=$n;$i++)
{$ans[$i]=$N_ion[$i];
push(@ans, $ans[$i]);
}
$answers = ~~@ans;
#
# Check student answers
#
&ANS(num_cmp($answers,reltol=>1,format=>'%0.4g') );

ENDDOCUMENT();
In reply to Eric Stroyan

Re: Too many answer blanks

by Danny Glin -
I've never seen num_cmp used in this way (to compare multiple answer blanks against an array of answers).

At some point in the past (likely between 2011 and now) num_cmp was rewritten to use MathObjects in the background, which potentially broke this question.

One suggestion is to put the answer checkers in the same for loop that generates the question text:

for ($i=0;$i<=$n;$i++)
{
BEGIN_TEXT
Number of $name_ion[$i] ions = \{ans_rule(5)\}. $BR
END_TEXT
ANS(num_cmp($N_ion[$i],reltol=>1,format=>'%0.4g') );
}

In reply to Danny Glin

Re: Too many answer blanks

by Eric Stroyan -
That worked!
I dug out my old server (WW and PG 2.5 I think) the original code was working. Something did change.
Thanks again.