WeBWorK Problems


Re: contextFraction.pl

by Davide Cervone -
Number of replies: 0
There are several problems here. First, the 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:

    ##Type of

    # "compoundProblem.pl",
    # "unionLists.pl",
    #for currency use Context("Currency") then Currency($A);
    #Then, in the text use $DOLLAR $a
    $showPartialCorrectAnswers = 1;


    $a1=random (3,7,2);
    $b1=random (4,8,4);
    $a2=random (4,8,2);
    $b2=random (5,7,2);
    $a3=random (3,9,3);
    $b3=random (5,10,5);
    #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);

    Evaluate each expression if \(x =\frac{$a1}{$b1}\), \(y=\frac{$a2}{$b2}\), and
    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
    a) \(x-y=\) \{ans_rule(6)\}
    b) \(x+2y=\) \{ans_rule(6)\}
    c) \(x+y+z=\) \{ans_rule(6)\}



Hope that clears things up.