RestrictedStudentAnswers

From WeBWorK_wiki
Revision as of 10:08, 19 October 2011 by Glarose (talk | contribs) (Created page with '<h2>Restricting Allowed Student Answer Formats: PG Code Snippet</h2> <!-- Header for these sections -- no modification needed --> <p style="background-color:#eeeeee;border:b…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Restricting Allowed Student Answer Formats: PG Code Snippet


This PG code shows how to check student answers that are equations. Note that this is an insertion, not a complete PG file. This code will have to be incorporated into the problem file on which you are working.

In general, there are a number of different restrictions that one might want to place on a student answer: that it be completely simplified, that it be exact, etc. In the following we consider a number of these. Note that there are often many ways to accomplish the same goals, and the method suggested here may or may not be directly applicable to the case you are considering. Often using a Custom Answer Checker or setting a Custom Error Message will also be desirable.

Examples below:

Problem Techniques Index

Requiring that an answer be simplified to a constant

PG problem file Explanation
Context("Numeric");

$expr = Formula("sin(x)^2 + cos(x)^2");
$deriv = Compute(0);

Setup: The set up section has nothing out of the ordinary. Our variable $deriv is the derivative of $expr, which is of course zero.

BEGIN_TEXT
Find and simplify completely:
$BR
\(\frac{d}{dx}\left($expr\right) = \)
\{ ans_rule(25) \}
END_TEXT

Main Text: The problem text section of the file is as we'd expect.

$showPartialCorrectAnswers = 1;

ANS( $deriv->cmp(showTypeWarnings=>0) );

ENDDOCUMENT();

Answer Evaluation: Here we've turned off type warnings in the answer checking, so that a student entering an un-simplified answer (e.g., 2 sin(x) cos(x) + 2 cos(x) (-sin(x))) will have it marked wrong (but not get feedback that says "you should have entered a number").

Problem Techniques Index