FractionAnswer1

From WeBWorK_wiki
Revision as of 11:44, 4 April 2023 by Pstaabp (talk | contribs) (switch to PGML and remove answerFormatHelp.pl macro)
Jump to navigation Jump to search

Answer is a Fraction - Try the problem in WeBWorK

Click to enlarge

This PG code shows how to write a question in which the answer must be a fraction (rational number).


Templates by Subject Area

PG problem file Explanation

Problem tagging data

Problem tagging:

DOCUMENT();

loadMacros('PGstandard.pl','MathObjects.pl','contextFraction.pl',
  'PGML.pl','PGcourse.pl');

TEXT(beginproblem());

Initialization:

Context('Fraction-NoDecimals');

$answer = Compute('3/2');

Setup: The macro contextFraction.pl provides four contexts:

Context("Fraction");
Context("Fraction-NoDecimals");
Context("LimitedFraction");
Context("LimitedProperFraction");

For the differences among these, see the POD documentation contextFraction.pl

BEGIN_PGML
Simplify [` \displaystyle \frac{6}{4} `].

Answer = [_______________]{$answer->cmp(
  studentsMustReduceFractions=>1,
  reduceFractions=>1,
  allowMixedNumbers=>0, 
  )}

[@ helpLink('fractions') @]*
END_PGML

Main Text: There are many context flags that control how fraction answers are checked. See the POD documentation contextFraction.pl

BEGIN_PGML_SOLUTION
Solution explanation goes here.
END_PGML_SOLUTION

ENDDOCUMENT();

Solution:

Templates by Subject Area