WeBWorK Problems

parsermultianswer.pl

parsermultianswer.pl

by Stacy Hoehn -
Number of replies: 4
Several years ago, I created a series of problems involving fractions that use parserMultiAnswer.pl for answer checking.  These problems used to work correctly, but after updating our WeBWorK server last summer (using the virtual machine image), the warning copied below is now displayed when students submit their answers.   

WeBWorK Warnings

WeBWorK has encountered warnings while processing your request. If this occured when viewing a problem, it was likely caused by an error or ambiguity in that problem. Otherwise, it may indicate a problem with the WeBWorK system itself. If you are a student, report these warnings to your professor to have them corrected. If you are a professor, please consult the warning output below for more information.

Warning messages

  • Redundant argument in sprintf at line 312 of [TMPL]/macros/parserMultiAnswer.pl
  • Redundant argument in sprintf at line 314 of [TMPL]/macros/parserMultiAnswer.pl

Request information

TimeTue Jun 29 12:19:29 2021
MethodPOST
URI/webwork2/Hoehn_MAT_131/Arithmetic_with_Rational_Functions/1/


The version of parserMultiAnswer.pl that I have is the one currently posted on https://github.com/openwebwork/pg/blob/master/macros/parserMultiAnswer.pl.   

Does anyone have ideas about what's causing these warnings or how to get rid of them? Technically, the problems are still being graded correctly, but the warnings cause the students to question the system. 
In reply to Stacy Hoehn

Re: parsermultianswer.pl

by Danny Glin -

I don't see any warnings when I use MultiAnswer.  Can you post the code for a problem that gives you the warning?

In reply to Danny Glin

Re: parsermultianswer.pl

by Stacy Hoehn -
Danny, here is the code to one of the problems that gives the warning. All of the rest are pretty similar.

###########################
#  Initialization

DOCUMENT();

loadMacros(
"PGstandard.pl", 
"MathObjects.pl", 
"PGunion.pl",
"parserMultiAnswer.pl",
"PGcourse.pl",
"AnswerFormatHelp.pl"
);

TEXT(beginproblem());


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

Context("Numeric");
Context()->variables->are(x=>"Real");
Context()->{error}{msg}{"Operands of '*' can't be words"} = " ";

$a = random(1,6,1);
$b = random(1,5,1);
$bb = $b*$b;
$apb = $a + $b;
$fraction = "\frac{-$a}{x^2-$bb} + \frac{1}{x+$b} ";

$num = Formula("x-$apb");
$den = Formula("x^2-$bb");

$multians = MultiAnswer($num, $den)->with(
      singleResult => 1,
      allowBlankAnswers => 1,
      format => "(%s)/(%s)",
      tex_format => "\frac{%s}{%s}",
      checker => sub {
        my ( $correct, $student, $self, $ansHash ) = @_;
        my ( $f1stu, $f2stu ) = @{$student};
        my ( $f1, $f2 ) = @{$correct};
  
        Context("Numeric");
        $correct = Compute("$f1/$f2");
        $ansHash->{correct_ans} = $correct->string;
        $ansHash->{correct_ans_latex_string} = $correct->TeX;
  
        return [0,0] if $f1stu eq "" || $f2stu eq "";
        $self->{format} = Compute("$f1stu/$f2stu")->string;
   
        if ( ( $f1==$f1stu &&  $f2==$f2stu) || 
            (-$f1==$f1stu && -$f2==$f2stu) ) {
            return [1,1];
        } elsif ( $f1==$f1stu || -$f1==$f1stu) {
            return [0,0];
        } elsif ( $f2==$f2stu || -$f2==$f2stu ) {
            return [0,0];
        } elsif ((Compute("$f1*$f2stu") == Compute("$f1stu*$f2"))  ) {
            $self->context->setError("Your answer should be further simplified");
            return; # don't return values here (so message will show)
        } else {
            return [0,0];
        }
      }
    );



#  Display the fraction and answer blanks nicely
#
Context()->texStrings;
if ($displayMode eq 'TeX') {
  $showfraction =
  "\[ $fraction = ".$multians->ans_rule(10).$multians->ans_rule(10)." \]";
} else {
  $showfraction =
  ColumnTable(
  "\( \displaystyle $fraction = \)",
  $multians->ans_rule(20).$BR.$HR.$multians->ans_rule(20),
  indent => 0, separation => 10, valign => "MIDDLE"
  );
}
Context()->normalStrings;



#################################
#  Main text

Context()->texStrings;
BEGIN_TEXT
Perform the indicated operations.
Express your answer as a fraction.
$BR
$BR
$BCENTER
$showfraction
$ECENTER
$BR
$BR
$BITALIC 
Note: Your answer must be written as a reduced fraction.  Enter the numerator in the top answer blank, and the denominator in the bottom answer blank, using '1' for the denominator if appropriate.    
\{AnswerFormatHelp("formulas","Help Entering Formulas")\}
$EITALIC
END_TEXT
$showHint = 3;
Context()->texStrings;

BEGIN_HINT
If you need help adding or subtracting rational expressions, $BR
1) Ask your instructor or staff in the Math Study Center for help! $BR
2) Visit this webpage: \{ htmlLink( "http://www.purplemath.com/modules/rtnladd2.htm", "Adding or Subtracting Rational Expressions","TARGET='_blank'"   ) \}     $BR
END_HINT

Context()->normalStrings;


#################################
#  Answer evaluation

$showPartialCorrectAnswers = 1;

install_problem_grader(~~&std_problem_grader);

ANS( $multians->cmp() );



ENDDOCUMENT();
In reply to Stacy Hoehn

Re: parsermultianswer.pl

by Glenn Rice -
The problem is this line in the checker:
$self->{format} = Compute("$f1stu/$f2stu")->string;
Delete that and the error will go away. That line shouldn't be needed as the format will make the answer appear in the desired way in any case.