DigitsTolType

Digits TolType

This describes an alternative way for determining the tolerance type based on the number of digits.

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


Initialization: The tolType of type digits is built-in to MathObjects.

Context("Numeric")
Context()->flags->set(tolType=>'digits', tolerance=>3, tolTruncation=>1);
$answer = Real("pi");  Setup: • Ensure that the Numeric context is set. This only pertains to numbers. • The tolType=>'digits' switch to the digits tolerance. • The tolerance=>3 sets the number of digits to 3 (the default). • The tolTruncation parameter is either 1 (true) or 0 (false). Details are explained below. • The tolExtraDigits parameter sets the number of extra digits for checking answers. This is explained below. In short, this will set the answer checked to see if the student answer matches the correct answer to tolerance digits. For the example of pi, this will be 3.14. If there are extra digits, there are a few other parameters to check: • If tolTruncation is true (the default), the correct answer and student answer are both truncated to the number of digits + the extra digits (parameter tolExtraDigits). The result is that both 3.141 and 3.142 are accepted. • If tolTruncation is false, then only the answer that matches the number of digits + extra digits is valid. In this example, only 3.141 will be accepted. The default value of tolTruncation is true. BEGIN_PGML This section is with [|tolTruncation|] set to true (1). The exact answer is [\pi]. Enter 3.14, 3.15, 3.141, 3.142 to see if it accepts the answer. [\pi=][_]{$answer}

END_PGML

First Section: This tests the default characteristic of this answer checker. It should accept 3.14, 3.141 and 3.142 as correct, but not 3.15.


Context("Numeric");
Context()->flags->set(tolType=>'digits', tolerance=>3, tolTruncation=>0);
$answer2 = Real("pi");  Second block explanation: First, reset the context with Context("Numeric") and then the set flags are set except for tolTruncation=>0. BEGIN_PGML This section is with [|tolTruncation|] set to false (0). The exact answer is [\pi]. Enter 3.14, 3.15, 3.141, 3.142 to see if it accepts the answer. [\pi=][_]{$answer2}

END_PGML


Second Section: This tests the default characteristic of this answer checker. It should accept 3.14, 3.142 as correct, but not 3.141 or 3.15.

Context("Numeric");
$answer3 = Real("3.14");  Second block explanation: First, reset the context with Context("Numeric") and then the set flags are set except for tolTruncation=>0 as well as the tolExtraDigits=>2. BEGIN_PGML If we want to consider only answers to some number to digits. Enter 3.14, 3.15, 3.141, 3.142 to see if it accepts the answer. Enter [\pi] to the first 2 decimal places after the decimal point [_]{$answer3}