WeBWorK Main Forum

Webwork doesn't always know correct answer to display when using custom graders. How fix?

Webwork doesn't always know correct answer to display when using custom graders. How fix?

by Christian Seberino -
Number of replies: 2
When using custom graders, Webwork doesn't know what to display in the "The correct answer is:" field when student select "Show correct answers."

Any way to make Webwork display an override since custom graders are confusing it?

In the example below my custom grader strips whitespace, ignore capitalization differences and allows 2 possible answers. Webwork leaves
the correct answer field blank when students try to display the correct answer.


Context("ArbitraryString");
@string_answers = ("scalene", "scalene triangle");
$strings = Compute("")->cmp(checker => sub {
my ($temp1, $response, $temp2) = @_;
$response =~ s/^~~s+|~~s+$//g;
$response = lc($response);
foreach (@string_answers) {
if ($response eq lc($_)) {
return 1;
}
}

return 0;
});


Here is the question too...

BEGIN_PGML
What is the term for triangles that have no sides
of the same length?

[____________]{$strings}
END_PGML




In reply to Christian Seberino

Re: Webwork doesn't always know correct answer to display when using custom graders. How fix?

by Gavin LaRose -
Hi Christian,

Based on your code snippet, I'm guessing that the problem is that the MathObject that you're using to generate the checker doesn't specify an object. My guess is that if you had something like

  ...
  Compute("scalene")->cmp( checker => ... );
  ...

students would then see a correct answer ("scalene") when viewing the correct answers. I suspect that there's a way within the checker to set the correct answer to the student's response if it's correct, too; my guess is that this will work, but I haven't tested it:

  Context("ArbitraryString");
  @string_answers = ("scalene", "scalene triangle");
  $strings = Compute("scalene")->cmp(checker => sub {
  my ($correct, $student, $self) = @_;
  $student =~ s/^~~s+|~~s+$//g;
  $student = lc($student);
  foreach (@string_answers) {
    if (Compute($_) == $student) {
      $self->{correct_ans} = $_;
      return 1;
    }
  }
  return 0;
  });

Gavin

In reply to Gavin LaRose

Re: Webwork doesn't always know correct answer to display when using custom graders. How fix?

by Christian Seberino -
Ah, thank a million. Adding a nonzero length string fixed the problem.
Now my students can see the answers whey they take Webwork tests.

cs