LimitedPowers

From WeBWorK_wiki
Revision as of 23:59, 12 March 2010 by Pearson (talk | contribs)
Jump to navigation Jump to search

Restricting Allowed Powers (Exponents) in Student Answers


This PG code shows how to restrict the allowed powers in student answers.

You may also be interested in other limited contexts DisableFunctions


Problem Techniques Index

PG problem file Explanation
DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGcourse.pl",
"contextLimitedPowers.pl",
);

TEXT(beginproblem());

Initialization: Use contextLimitedPowers.pl to restrict what is allowed as arguments to exponentiation a^b.

Context("Numeric");

#LimitedPowers::NoBaseE();

#  chose one of these three:
#LimitedPowers::OnlyIntegers();
LimitedPowers::OnlyPositiveIntegers();
#LimitedPowers::OnlyNonNegativeIntegers();

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

Setup: This is the section where we restrict the allowed types of powers. For more options, see the POD documentation contextLimitedPowers.pl

Context()->texStrings;
BEGIN_TEXT
(a) Enter \( $a^3 \): \{ ans_rule(10) \}
$BR
(b) Enter \( 1/$a^3 \), not \( $a^{-3} \): \{ ans_rule(10) \}
$BR
(c) Enter \( 1/x^2 \), not \( x^{-2} \): \{ ans_rule(10) \}
END_TEXT
Context()->normalStrings;

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

$showPartialCorrectAnswers = 1;

ANS( Real("$a^3")->cmp() );
ANS( Real("1/$a^3")->cmp() );
ANS( Compute("1/x^2")->cmp() );

ENDDOCUMENT(); 

Answer Evaluation: As is the answer.

Problem Techniques Index