## WeBWorK Problems

### 2 contexts

by Charles Fortin -
Number of replies: 5
Hi,
I have created a problem where the answer is a list of points, but I would also like to force the answers to be entered as fractions. I have tried to use the two contexts Fraction-NoDecimals and Point (can I do this?) but it is not working, i.e. decimal answers are still accepted. Any ideas how I can fix this?

Charles

PS Here is my problem

# DESCRIPTION
# Solve a system of equation involving a product
# WeBWorK problem written by Charles Fortin,
# <cfortin(at)champlaincollege.qc.ca(dot)ca>
# ENDDESCRIPTION

## DBsubject('WeBWorK')
## DBchapter('Demos')
## DBsection('Problem')
## KEYWORDS('')
## TitleText1('')
## EditionText1('')
## AuthorText1('')
## Section1('')
## Problem1('')
## Author('Charles Fortin')
## Institution('ChamplainCollege')

DOCUMENT();
"PGstandard.pl",
"MathObjects.pl",
"PGchoicemacros.pl",
"contextFraction.pl",
"contextLimitedPoint.pl",
);

# This problem requires the student to solve
# xy=h; (x-k)*(y-l)=q;
# The solutions are solutions of the equation
# lx^2+(q-kl-h) + kh=0
# Since lkh = mn and q-kl-h=m+n, the quadratic
# on the left-hand side can be factored as
# 1/l(lx+m)(lx+h)

# make sure we're in the context we want

Context("Fraction-NoDecimals");
$l = random(1,3);$k = random(1,3);
$h = random(1,3);$m = Compute("$l*$k");
$n = Compute("$h");
$q = Compute("2*($m+$n)");$ans1x = Compute("-$m/$l");
$ans1y = Compute("-($h*$l)/$m");
$ans2x = Compute("-$h/$l");$ans2y = Compute("-$l"); Context("Point");$answer = List( Point("($ans1x,$ans1y)"), Point("($ans2x,$ans2y)") );

TEXT(beginproblem());
Context()->texStrings;
BEGIN_TEXT
Solve the system of equations
$\left\lbrace \begin{array}{ccc} xy &=& h \\ (x-k)(y-l) &=& q \end{array} \right.$

Enter a solution as $$(x,y)$$,
including the parentheses. If there is more
than one correct answer, enter a comma
separated list of points. If there are no answer, enter
${BBOLD}none$EBOLD.
$BR$BCENTER
(x,y): \{ ans_rule(20) \}
$ECENTER END_TEXT Context()->normalStrings; ANS($answer->cmp() );

Context()->texStrings;
SOLUTION(EV3(<<'END_SOLUTION'));
$PAR SOLUTION$PAR

END_SOLUTION
Context()->normalStrings;

ENDDOCUMENT();

### Re: 2 contexts

by Alex Jordan -
When you set the context to "Point" you lost the fraction restrictions. Instead, within the Fraction context, set the meaning of parentheses to denote Points. It's confusing, because Point is both a context and a Math Object. But you want he Point Math Object, not the Point Context.

Context()->parens->set('('=>{type=>'Point'});
$answer = Compute("($ans1x,$ans1y),($ans2x,\$ans2y)" );

After making this change, the problem almost works. It accepts correct answer and rejects any with decimals, all the while giving the right feedback messages.

I get a pink screen though and error messages saying that there is something wrong with the constants i, j, and k. I'm not sure how to address that. Maybe someone else knows?

### Re: 2 contexts

by Davide Cervone -
That was going to be my suggestion as well. It seems to work for me. I don't get any pick screen or message about i, j, and k. Can you provide the complete problem file that you are using?

### Re: 2 contexts

by Alex Jordan -
Hmm. I work off of a server running 2.4, and I also can't say anything about how up-to-date contextFraction.pl is. Or any of the other .pl and .pm files that are in play for that matter.

I would guess that one of these things is the source of my pink screen. I literally copied and pasted Charles's code and replaced the two lines as in my post.