## WeBWorK Problems

by D. Brian Walton -
Number of replies: 1
I believe that ProblemRandomize does not correctly dispose of previous information when the MultiAnswer parser is used.  Below is an example .pg code that illustrates this issue.  When a correct answer is submitted and then a new random problem is requested, the first answer blank for the MultiAnswer is cleared, but the second answer blank continues to show the most recent submitted answer.

I went to see if I could see an obvious solution, but I realized I would need to understand how WW maintains information between queries.  I thought someone else might be better suited to find the error.

Brian Walton

-----------------

DOCUMENT();        # This should be the first executable line in the problem.

"PGstandard.pl",
"MathObjects.pl",
"problemRandomize.pl"
);

TEXT(beginproblem);

###################################
# Setup

Context("Numeric");
$pr = ProblemRandomize(onlyAfterDue=>0); # Answer$k = random(10,20);

$exA = Real(random(1,$k-1,1));
$exB = Real($k-$exA);$multipart = MultiAnswer($exA,$exB)->with(
singleResult => 1,
checker => sub {
my ( $correct,$student, $self ) = @_; my ($stuA, $stuB ) = @{$student};
my ( $exA,$exB ) = @{$student};$zero = Real(0);
if ($stuA ==$zero) {
$self->setMessage(1, "Do not use zero."); return 0; } elsif ($stuB == $zero) {$self->setMessage(2, "Do not use zero.");
return 0;
} else {
return ($stuA+$stuB == $exA+$exB);
}
}
);

BEGIN_TEXT
Give two non-zero numbers $$a$$ and $$b$$ so that $$a+b = k$$.

$PAR $$a =$$\{$multipart->ans_rule(5) \}
and
$$b =$$ \{ $multipart->ans_rule(5) \}. END_TEXT ################################### # Answer checking$showPartialCorrectAnswers = 0;
ANS(\$multipart->cmp);

###################################

ENDDOCUMENT();        # This should be the last executable line in the problem.;
In reply to D. Brian Walton