Difference between revisions of "FractionAnswer1"

From WeBWorK_wiki
Jump to navigation Jump to search
(22 intermediate revisions by 4 users not shown)
Line 1: Line 1:
<h2>Answer is a Fraction</h2>
 
  +
<h2>Answer is a Fraction - [https://testcourses.webwork.maa.org/webwork2/Problem_Authoring_Techniques/T-PP-Algebra/1 <font size=-1> Try the problem in WeBWorK </font> ]</h2>
   
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;">
 
  +
[[File:FractionAnswer1.png|300px|thumb|right|Click to enlarge]]
This PG code shows how to ...
 
  +
<p style="background-color:#f9f9f9;border:black solid 1px;padding:3px;">
<ul>
 
  +
This PG code shows how to write a question in which the answer must be a fraction (rational number).
<li>Download file: [[File:FractionAnswer1.txt]] (change the file extension from txt to pg)</li>
 
<li>File location in NPL: <code>NationalProblemLibrary/FortLewis/Authoring/Templates/Algebra/FractionAnswer1.pg</code></li>
 
</ul>
 
 
</p>
 
</p>
  +
* File location in OPL: [https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/Algebra/FractionAnswer1.pg FortLewis/Authoring/Templates/Algebra/FractionAnswer1.pg]
  +
* PGML location in OPL: [https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/Algebra/FractionAnswer1_PGML.pg FortLewis/Authoring/Templates/Algebra/FractionAnswer1_PGML.pg]
   
  +
<br clear="all" />
 
<p style="text-align:center;">
 
<p style="text-align:center;">
 
[[SubjectAreaTemplates|Templates by Subject Area]]
 
[[SubjectAreaTemplates|Templates by Subject Area]]
Line 41: Line 41:
 
<pre>
 
<pre>
 
DOCUMENT();
 
DOCUMENT();
  +
 
loadMacros(
 
loadMacros(
 
"PGstandard.pl",
 
"PGstandard.pl",
  +
"MathObjects.pl",
 
"contextFraction.pl",
 
"contextFraction.pl",
 
"AnswerFormatHelp.pl",
 
"AnswerFormatHelp.pl",
 
);
 
);
  +
 
TEXT(beginproblem());
 
TEXT(beginproblem());
 
</pre>
 
</pre>
Line 77: Line 80:
 
Context("LimitedProperFraction");
 
Context("LimitedProperFraction");
 
</pre>
 
</pre>
For the differences among these, see the POD documentation [http://webwork.maa.org/pod/pg_TRUNK/macros/contextFraction.pl.html contextFraction.pl.html]
+
For the differences among these, see the POD documentation [http://webwork.maa.org/pod/pg/macros/contextFraction.html contextFraction.pl]
 
</p>
 
</p>
 
</td>
 
</td>
Line 114: Line 117:
 
ANS( $answer->cmp(
 
ANS( $answer->cmp(
 
studentsMustReduceFractions=>1,
 
studentsMustReduceFractions=>1,
reduceFractions=>1
+
reduceFractions=>1,
  +
allowMixedNumbers=>0,
 
)
 
)
 
);
 
);
Line 121: Line 124:
 
<p>
 
<p>
 
<b>Answer Evaluation:</b>
 
<b>Answer Evaluation:</b>
  +
There are many context flags that control how fraction answers are checked. See the POD documentation [http://webwork.maa.org/pod/pg/macros/contextFraction.html contextFraction.pl]
 
</p>
 
</p>
 
</td>
 
</td>
Line 133: Line 137:
 
Context()->texStrings;
 
Context()->texStrings;
 
BEGIN_SOLUTION
 
BEGIN_SOLUTION
  +
${PAR}SOLUTION:${PAR}
 
Factor and cancel to obtain
 
Factor and cancel to obtain
 
\( \displaystyle $answer \)
 
\( \displaystyle $answer \)
Line 153: Line 158:
   
 
[[Category:Top]]
 
[[Category:Top]]
[[Category:Authors]]
+
[[Category:Sample Problems]]
  +
[[Category:Subject Area Templates]]

Revision as of 17:45, 7 April 2021

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",
"AnswerFormatHelp.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

Context()->texStrings;
BEGIN_TEXT
Simplify \( \displaystyle \frac{6}{4} \).
$BR
$BR
Answer =
\{ ans_rule(20) \}
\{ AnswerFormatHelp("fractions") \}
END_TEXT
Context()->normalStrings;

Main Text:

$showPartialCorrectAnswers = 1;

ANS( $answer->cmp(
  studentsMustReduceFractions=>1,
  reduceFractions=>1,
  allowMixedNumbers=>0, 
  ) 
);

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


Context()->texStrings;
BEGIN_SOLUTION
${PAR}SOLUTION:${PAR}
Factor and cancel to obtain 
\( \displaystyle $answer \)
END_SOLUTION
Context()->normalStrings;

ENDDOCUMENT();

Solution:

Templates by Subject Area