Difference between revisions of "AnyAnswerMarkedCorrect"

From WeBWorK_wiki
Jump to navigation Jump to search
m
m
Line 207: Line 207:
 
</table>
 
</table>
 
<p style="text-align:center;">
 
<p style="text-align:center;">
[[IndexOfProblemTechniques|Problem Techniques Index]]
+
[[Problem_Techniques|Problem Techniques Index]]
 
</p>
 
</p>
   

Revision as of 14:04, 21 June 2013

Any Answer Marked Correct


This PG code shows how to mark any answer a student submits as correct. There are, as usual, many ways to do this; we show two here, one using a custom answer checker, and one using a special answer checker that marks any answer correct.

Problem Techniques Index

With the Special Answer Checker

PG problem file Explanation
DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGasu.pl",
"PGcourse.pl",
);
TEXT(beginproblem()); 

Initialization: We need to include the macros file PGasu.pl, which provides an answer checker that marks any answer submitted as correct.

Context("Numeric");

$a = random(2,9,1);

Setup: Everything is as usual.

Context()->texStrings;
BEGIN_TEXT
Enter anything, e.g. \($a\) and
it will be marked correct:
\{ans_rule(10) \}.


END_TEXT
Context()->normalStrings;

Main Text: The text section is as we'd expect.

$showPartialCorrectAnswers = 1;

ANS(auto_right("All answers are marked correct"));

ENDDOCUMENT();

Answer Evaluation: We use the ANS(auto_right("All answers are marked correct")); routine to evaluate the answer. The phrase in quotes (which can be empty) is displayed when "Show correct answers" is checked. See PGasu.pl.html for more options and details.

With a Custom Checker

PG problem file Explanation
DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
);
TEXT(beginproblem()); 

Initialization: No additions are needed to the initialization section of the file.

Context("Numeric");

$a = Compute(random(2,9,1));

Setup: Everything is as usual. In this case we are going to need a MathObject to do the answer checking, so create one here.

Context()->texStrings;
BEGIN_TEXT
Enter any number, e.g. \($a\) and it
 will be marked correct:
\{ans_rule(10) \}.


END_TEXT
Context()->normalStrings;

Main Text: The text section is as we'd expect.

$showPartialCorrectAnswers = 1;

ANS( $a->cmp( checker=>sub {
    my ( $cor, $stu, $ans ) = @_;
    return 1; } ) );

ENDDOCUMENT();

Answer Evaluation: We use our MathObject to check the answer, but specify a custom answer checker to do the actual checking. Here we return 1 for any answer, so anything will be marked correct. One note about this method: because our MathObject is a real number, it will require that the student's answer be a real number to be marked correct. We could accept any formula or number by specifying $a = Formula(random(2,9,1)) above.

It should also be possible to turn off type checking---we need to document this.

Problem Techniques Index