Depending
on what you want, you might be able to solve your problem by taking
this as a multivariable function and let WeBWork test it as such. Then
it should accept any algebraically equivalent form.
If you don't want to do that, here is an answer evaluator which might
do what you want. It allows the problem writer to specify several
answer evaluators. It will test them in turn until it hits one where
the student would get some credit and uses that. If they all fail, the
student gets no credit.
You can also specify a weight for each answer. For example, a match
against one answer might be worth full credit, but if that fails,
another match should be worth half credit. One might use this if they
were going to ask students to simplify a numerical answer, but give
partial credit for an unsimplified answer.
And that's not all. You also can specify a comment to go with each
answer. In the scenerio of the last paragraph, a student who gets half
credit might appreciate a comment saying that if they go back and
simplify the number themselves they can get full credit.
So, the input to this answer evaluator is basically a list of triples
(answer evaluator, weight for partial credit, comment). Technically it
is not a list but a perl reference to an array. So, you might call it
with:
&ANS(pc_evaluator([[std_num_cmp(3), 1, 'Full Credit!'],
[std_num_cmp(2),0.5,'Half'], [std_num_cmp(1), 0.1, 'Barely any credit
:(']]));
The pc stands for partial credit. The code is below. Comments and suggestions are welcome.
John Jones
-------------------------------
sub pc_evaluator { my ($evaluator_list) = @_;
my $ans_evaluator = sub { my $tried = shift; my $ans_hash; for($j=0;$j<scalar(@{$evaluator_list}); $j++) { my $old_evaluator = $evaluator_list->[$j][0]; my $cmt = $evaluator_list->[$j][2]; my $weight = $evaluator_list->[$j][1];
if ( ref($old_evaluator) eq 'AnswerEvaluator' ) { # new style $ans_hash = $old_evaluator->evaluate($tried); } elsif (ref($old_evaluator) eq 'CODE' ) { #old style $ans_hash = &$old_evaluator($tried); } else { warn "There is a problem using the answer evaluator"; }
if($ans_hash->{score}>0) { $ans_hash -> setKeys( 'ans_message' => $cmt); $ans_hash->{score} *= $weight; return $ans_hash; }; }; return $ans_hash; };
$ans_evaluator; }
<| Post or View Comments |>
|