## WeBWorK Main Forum

by Lijuan Cao -
Number of replies: 1

I am creating questions for composition of relations, where students are expected to enter a list of ordered pairs as answers. I noticed that the answer check for multiple ordered pairs would work, but it fails when there is only one pair in the answer. Below is an example, the answer of (a,b) for the first question is marked wrong, but the answer of (a,b), (c,d) for the second question is marked correct. I also attached a screenshot of the answer checker. Is there a way to fix this problem? Thanks.

Context("Numeric");

foreach my $i(a..z) { Context()->strings->add($i=>{});

}

$a1 = Compute("(a,b)");$a2 = Compute("(a,b), (c,d)");

BEGIN_PGML

Enter [(a, b)] [____________]

Enter [(a, b), (c, d)] [____________]

END_PGML

$showPartialCorrectAnswers = 1; ANS($a1->cmp(entry_type=>"pair"));
ANS($a2->cmp(entry_type=>"pair")); In reply to Lijuan Cao ### Re: Answer checker question by Danny Glin - Here's what I was able to determine: The Compute function parses the string you pass it and tries to determine what type of object it is. Because you are in the Numeric context it is expecting numbers (and the strings you have added), so it is interpreting (a,b) as a list of strings/numbers. Thus it accepts either a,b or b,a (without parentheses) as a correct answers. If a student includes parentheses in their submitted answer, it assumes that they intended to enter a point, so it complains about the wrong type of input. It's worth noting that (as far as I can tell) the entry_type flag doesn't change the behaviour of the answer checker. It simply changes the feedback messages to students. The Point context is probably closer to what you want, but there are at least two problems: 1. The Point context doesn't support strings, and 2. The error messages will talk about points and not pairs. The following code at least appears to grade things properly (marking correct answers correct and incorrect answers wrong), but the error messages when a student enters something in the wrong format are not what you want. Context("Point"); foreach my$i(a..w) {
Context()->variables->add($i=>"Real"); }$a1 = Compute("(a,b)");
$a2 = Compute("(a,b), (c,d)"); BEGIN_PGML Enter [(a, b)] [____________] Enter [(a, b), (c, d)] [____________] END_PGML # Answer evaluation$showPartialCorrectAnswers = 1;
ANS($a1->cmp(entry_type=>"pair")); ANS($a2->cmp(entry_type=>"pair"));