## WeBWorK Problems

by Kenneth Appel -
Number of replies: 2
For a grade school problem like
"Write a decimal number that is more than 1 but less than 2." I need an answer evaluator that accepts as an answer any number in an interval. Does one already exist or must I write one?

by Bruce Yoshiwara -
Hi Kenneth,

I modified what Davide gave me in this forum when I asked about allowing on correct value out of many...This might work:

DOCUMENT();
"PGstandard.pl", # Standard macros for PG language
"MathObjects.pl",
"contextFraction.pl",
);

TEXT(beginproblem());

Context("Fraction");

BEGIN_TEXT
A decimal number between 0 and 1 is \{ans_rule(20)\}
END_TEXT
ANS(Compute("0.5")->cmp(
checker => sub {
my ($correct,$student,$ans) = @_; my ($x) = $student->value; return$x >0 && $x In reply to Bruce Yoshiwara ### Re: answer evaluators by Davide Cervone - I think Bruce's answer was truncated. (You have to be careful when entering less-than signs, or Moodle will think they are part of a tag and possibly remove them. If there is no matching greater-than to end the tag, the whole rest of the message can be lost, as in this case). I think Bruce was going to say to use  ANS(Compute("0.5")->cmp( checker => sub { my ($correct,$student,$ans) = @_;
my $x =$student->value;
return $x > 1 &&$x  < 2;
}));

which is essentially what I was going to suggest as well.

There is an issue to consider, however, and that's the use of $student->value rather than $student itself. If one uses $student, then the MathObject's fuzzy real comparisons will be used, so that values that are fuzzy-equal to 1 or 2 will be excluded (i.e., the check is really more like $x > 1+epsilon && \$x < 2-epsilon). The difference would be whether you expect students to enter a computed value (a numeric formula) or to type a decimal directly. If it is a formula that they will be computing, you might want to use the fuzzy check, so that something that computes 1.99999 (but should have been 2 had it not been for round-off errors) will not be counted as correct, as it would when the non-fuzzy check it performed.

I'm not sure which I think is the right approach. It really depends on the problem, how you expect students to approach it, and how likely you think answers near the endpoints will be.

Davide