I used the context

Context("Fraction")->flags->set(

requireProperFractions =>1,

reduceConstants => 0, #keep fractions and operations between them

);

The answer 41/20 was accepted as correct (without comment.)

What did I do wrong?

answers shown are mixed numbers, but entries that are not

mixed numbers are accepted, for example

Entered | Answer Preview | Correct | Result |
---|---|---|---|

9/20 | incorrect | ||

2.85 | 2 17/20 | correct | |

3 17/20 | 3 17/20 | correct |

Evaluate each expression if

Your answer should be a reduced fraction or a mixed number with the

faction part reduced (A mixed number can be entered in the form 2 3/4 to mean ).

a)

b)

c)Note that the 77/20 is converted to 3 17/20 but not rejected for improper form and 2.85 is accepted even

though it is a decimal.

Here is the code

DESCRIPTION

##Type of

#ENDDESCRIPTION

DOCUMENT();

loadMacros(

"PGstandard.pl",

"PGchoicemacros.pl",

#"PGgraphmacros.pl",

"MathObjects.pl",

# "compoundProblem.pl",

#"contextCurrency.pl",

#"contextInequalities.pl",

#"unionTables.pl",

# "unionLists.pl",

#"unionMacros.pl",

#"contextLeadingZero.pl",

"contextFraction.pl",

"answerHints.pl",

"problemPanic.pl",

#"PGauxiliaryFunctions.pl", #for lcm, gcd,etc

);

#for currency use Context("Currency") then Currency($A);

#Then, in the text use $DOLLAR $a

TEXT(beginproblem());

$showPartialCorrectAnswers = 1;

Context("Fraction")->flags->set(allowProperFractions =>1,

requireProperFractions =>1, showProperFractions=>1 ,

reduceConstants => 0, #keep fractions and operations between them

);

$a1=random (3,7,2);

$b1=random (4,8,4);

$x=Compute("$a1/$b1");

$a2=random (4,8,2);

$b2=random (5,7,2);

$y=Compute("$a2/$b2");

$a3=random (3,9,3);

$b3=random (5,10,5);

$z=Compute("$a3/$b3");

$ans1=$x-$y;

$ans2=$x+2*$y;

$ans3=$x+$y+$z;

#warn "a1=$a1, b1=$b1, x=$x, a2=$a2, b2=$b2, y=$y, a3=$a3, b3=$b3, z=$z, a1=$ans1";

BEGIN_TEXT

Evaluate each expression if \( x =\frac{$a1}{$b1},\ y=\frac{$a2}{$b2},\ and\

z=\frac{$a3}{$b3}\)

$BR Your answer should be a reduced fraction or a mixed number with the $BR

faction part reduced (A mixed number can be entered in the form 2 3/4 to mean

\(2\frac{3}{4}\) ).$PAR

$PAR

a) \(x-y=\ \ \) \{ans_rule(6)\}

$PAR

b) \(x+2y=\ \ \) \{ans_rule(6)\}

$PAR

c) \(x+y+z=\ \ \) \{ans_rule(6)\}

END_TEXT

Context("LimitedFraction")->flags->set(allowProperFractions =>1,

requireProperFractions =>1, showProperFractions =>1,

reduceConstants => 0, #keep fractions and operations between them

);

ANS($ans1->cmp);

ANS($ans2->cmp);

ANS($ans3->cmp);

ENDDOCUMENT()

`requireProperFractions`flag requires the

`strictFractions`flag, so it is really only effective in the

`LimitedFraction`context, not in the plain

`Fraction`context. Also, if you were to get this flag to work

`Fraction`context (by setting

`strictFraction`), then you would not be able to enter the improper fractions that you do in the

`Compute()`calls below.

Second, the `LimitedFraction` context that you set at the bottom has no effect. This is because MathObjects retain the context in which they were created, so since `$ans1`, `$ans2`, and `$ans3` where created in the `Fraction` context, they continue to be in that context even after you change the current context to `LimitedFraction`.

The proper way to do this is to create them in `LimitedFraction` context initially (*without* the `requireReducedFractions` flag set, so the correct answer can be entered as an improper fraction) and then set the `requireReducedFractions` flag after they are created.

Here is the code:

#DESCRIPTION ##Type of #ENDDESCRIPTION DOCUMENT(); loadMacros( "PGstandard.pl", #"PGchoicemacros.pl", #"PGgraphmacros.pl", "MathObjects.pl", # "compoundProblem.pl", #"contextCurrency.pl", #"contextInequalities.pl", #"unionTables.pl", # "unionLists.pl", #"unionMacros.pl", #"contextLeadingZero.pl", "contextFraction.pl", #"answerHints.pl", #"problemPanic.pl", ); #for currency use Context("Currency") then Currency($A); #Then, in the text use $DOLLAR $a TEXT(beginproblem()); $showPartialCorrectAnswers = 1; Context("LimitedFraction"); $a1=random (3,7,2); $b1=random (4,8,4); $x=Compute("$a1/$b1"); $a2=random (4,8,2); $b2=random (5,7,2); $y=Compute("$a2/$b2"); $a3=random (3,9,3); $b3=random (5,10,5); $z=Compute("$a3/$b3"); $ans1=$x-$y; $ans2=$x+2*$y; $ans3=$x+$y+$z; #warn "a1=$a1, b1=$b1, x=$x, a2=$a2, b2=$b2, y=$y, a3=$a3, b3=$b3, z=$z, a1=$ans1"; Context()->flags->set(requireProperFractions => 1); BEGIN_TEXT Evaluate each expression if \(x =\frac{$a1}{$b1}\), \(y=\frac{$a2}{$b2}\), and \(z=\frac{$a3}{$b3}\).$BR Your answer should be a reduced fraction or a mixed number with the $BR faction part reduced (a mixed number can be entered in the form 2 3/4 to mean \(2\frac{3}{4}\)).$PAR $PAR a) \(x-y=\) \{ans_rule(6)\} $PAR b) \(x+2y=\) \{ans_rule(6)\} $PAR c) \(x+y+z=\) \{ans_rule(6)\} END_TEXT ANS($ans1->cmp); ANS($ans2->cmp); ANS($ans3->cmp); ENDDOCUMENT();

Hope that clears things up.

Davide

`requireProperFractions`flag only works when the

`strictFractions`flag is also set. This is not properly documented in the file, but I will fix that.

Davide