WeBWorK Problems

Can upToConstant and withPostFilter be used together?

Can upToConstant and withPostFilter be used together?

by Larry Riddle -
Number of replies: 2

I'm trying to capture two things in checking a student's answer to a particular type of question.

1. I want to allow "up to a constant" in the correct answer.

2. I want to catch a particular wrong answer and give a special message.

I've tried the following (simplified) approach:

[_]{$ans->cmp(upToConstant=>1)->withPostFilter(AnswerHints( Formula("x")=>"the message"))}

With the "upToConstant=>1" option, the correct answer + a constant is marked correct, but the answer "x" does not produce the answerhint message.

Without the "upToConstant=>1" option, the answerhint works to give the message, but the correct answer + a constant is now marked as incorrect.

Is there another way to achieve both goals? While it would be nice if "x + 2" also produced the answerhint message, I could live without that.


In reply to Larry Riddle

Re: Can upToConstant and withPostFilter be used together?

by Danny Glin -

One way to do this is to manually define an adaptive parameter in the context rather than using upToConstant:

Context()->variables->add('C'=>"Parameter");
$ans = Formula("x^2+C");

BEGIN_PGML
[_]{$ans->cmp->withPostFilter(AnswerHints( Formula("x+C")=>"the message"))}
END_PGML


In reply to Danny Glin

Re: Can upToConstant and withPostFilter be used together?

by Larry Riddle -
Thank you, Danny. Using an adaptive parameter does exactly what I wanted for the two goals.