## WeBWorK Main Forum

### Bug trying to make grader in PGML problem give partial credit for wrong units.

by Christian Seberino -
Number of replies: 1
I'm trying to modify a working PGML problem below to give partial credit if
numerical part of answer is right but units are wrong.
(Give only 75% of old score if units missing or incorrect.)

I'm aware of the withPostFilter method of "answerHints.pl"
but not sure how to integrate the ANS(...) piece into this PGML
problem.

Furthermore, withPostFilter is normally used to give hints so I'm not
sure if I'm tweaking it appropriately to just change score.

Right now below gives this error...

panic: sv_setpvn called with negative strlen -2 at /opt/webwork/pg/lib/WeBWorK/PG/Translator.pm line 788

DOCUMENT();
"MathObjects.pl",
"PGstandard.pl",
"PGML.pl",
"PGcourse.pl",
"parserNumberWithUnits.pl",
"contextArbitraryString.pl",
"parserPopUp.pl",
"contextInequalities.pl",
);
TEXT(beginproblem());
$showPartialCorrectAnswers = 1; ###################################################################### Context("Numeric") ; Context()->flags->set(tolerance => 0.01);$ans = NumberWithUnits("2 ft");

ANS($ans->cmp()->withPostFilter( if ($ans->{student_ans} =~ /ft\z/) {
$ans->{score} = 0.75 *$ans->{score};
});

BEGIN_PGML
How many feet are equal to 24 inches?

[________________________]{\$ans}
END_PGML

######################################################################
ENDDOCUMENT();