## WeBWorK Main Forum

### Re: How make Webwork give partial credit for "almost right" answers e.g. wrong units or off by just a minus sign?

by Davide Cervone -
Number of replies: 0
The answerHints.pl macro file can be used to do this. See the documentation for answerHints for some details. There are also examples in the wiki.

The basic idea is that you provide answers for which you want to give some helpful message or partial credit, and supply the message or credit that you want to give for that. So

    loadMacros("answerHints.pl");

$n = Compute("sqrt(2)"); BEGIN_TEXT$n = \{ans_rule(10)\}
END_TEXT

ANS($n->cmp->withPostFilter(AnswerHints( -$n => ["Check the sign of your answer",score=>.25]
)));

would give 25% credit for the negative of the correct answer, and provide a message to check the sign. If you don't want the message, you can make it blank, i.e., "".

You can provide a list of such hints, and you can even provide a subroutine that determines when the hint is to be applied (rather than a fixed value), so

    loadMacros("answerHints.pl");

$n = Compute("sqrt(2)"); BEGIN_TEXT$n = \{ans_rule(10)\}
END_TEXT

ANS($n->cmp->withPostFilter(AnswerHints( sub { my ($correct,$student,$ans) = @_;
return \$student  ["Check the sign of your answer"]
)));

would give the sign warning for any negative number.

Hope that helps.

Davide