WeBWorK Problems

Require a non-mixed number in Fraction context while keeping mixed number syntax

Require a non-mixed number in Fraction context while keeping mixed number syntax

by Adam Weyhaupt -
Number of replies: 4
For some questions written for a class in "math for elementary teachers", we need to be able to require a non-mixed number answer while allowing webwork to interpret a b/c as the mixed number a + b/c.

For example, we would like to have students compute 7/2 * 1/3, and the only acceptable answer is 7/6.

I tried just setting allowProperFractions to 0, but then when a student enters 1 1/6 their answer is parsed as 1/6. I'd like the answer 1 1/6 to be parsed as 1 1/6 but marked INCORRECT.

The only thing that I can think of is to use a custom answer checker and check to see whether or not their answer contains blanks. If it does, then the answer should be marked incorrect. If it does not, then let the standard cmp method determine whether the answer is correct or not.

Does this make any sense? Is there a better way?

Thanks!

Adam
In reply to Adam Weyhaupt

Re: Require a non-mixed number in Fraction context while keeping mixed number syntax

by Davide Cervone -
Sorry for the long delay in getting back to you on this. There was no easy way to do this (I don't recommend the "check for space" approach, as the student can have leading or trailing spaces, for example). It would be better to look at the parse tree, but that has some wrinkles you'd have to be careful about.

In any case, I added a new flag, requirePureFraction, that should do what you want. This flag will cause an error message if a mixed number is entered, assuming mixed numbers are being parsed; i.e., that allowMixedNumbers is true (allowProperFractions was renamed allowMixedNumbers, but probably should have been called something like parseMixedNumbers in light of the new arrangement where they be "allowed" (i.e., properly parsed) but required not to be used).

You will have to get the most recent update of pg/macros/contextFraction.pl in order to take advantage of the new flag.

Hope that does the trick.

Davide
In reply to Davide Cervone

Re: Require a non-mixed number in Fraction context while keeping mixed number syntax

by Adam Weyhaupt -
Davide -

Thanks for your work on this on.

I'm not able to get this to work; in the example below if I enter "8 7/8" it is accepted as correct without complaint. The "entered box" shows 71/8. I'm sure I'm missing something simple! I'm using contextFraction.pl version 1.14.

Thanks for any help you can provide!

Below is a minimal example that exhibits the problem.

Adam

---


DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"contextFraction.pl",
);


$c1 = 8;
$n1 = 7;
$n2 = 8;

Context("Fraction");
Context()->flags->set(allowMixedNumbers=>1);
Context()->flags->set(showMixedNumbers=>0);
Context()->flags->set(reduceConstants=>0);
Context()->flags->set(requirePureFraction=>1);

$ans = Fraction($c1*$n2 + $n1, $n2);


Context()->texStrings;
BEGIN_TEXT

\( $c1 \frac{$n1}{$n2}= \) \{ans_rule(35) \}

END_TEXT
Context()->normalStrings;

ANS($ans->cmp);

ENDDOCUMENT();
In reply to Adam Weyhaupt

Re: Require a non-mixed number in Fraction context while keeping mixed number syntax

by Davide Cervone -
The flag is "requirePureFractions" not "requirePureFraction" (plural not singular). I mistyped it in my message above, but if you change it, I think that will work for you.

Davide
In reply to Davide Cervone

Re: Require a non-mixed number in Fraction context while keeping mixed number syntax

by Adam Weyhaupt -
Oh my, that's embarrassing ... thanks for the kind help! This works perfectly, of course. (I even looked at the code but didn't catch this...)

Adam