WeBWorK Problems

parserMultiAnswer and problemRandomize

parserMultiAnswer and problemRandomize

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
James Madison University

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

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

loadMacros(
  "PGstandard.pl",
  "MathObjects.pl",
  "parserMultiAnswer.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

Re: parserMultiAnswer and problemRandomize

by Davide Cervone -
You are correct, there is a problem with mixing these two objects. It turns out that the MultiAnswer object uses normal answer blanks for the first answer, but special ones for the second and later answers, and the ProblemRandomize was only clearing the normal answer blanks. I have modified problemRandomize.pl to resolve the issue. You will need to get the latest HEAD version of pg/macros/problemRandomize.pl to obtain the fix.

Davide