WeBWorK Problems

2 contexts

2 contexts

by Charles Fortin -
Number of replies: 5
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?


PS Here is my problem

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

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


# 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

$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");

$answer = List( Point("($ans1x,$ans1y)"), Point("($ans2x,$ans2y)") );

Solve the system of equations
xy &=& $h \\
(x-$k)(y-$l) &=& $q

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
(x,y): \{ ans_rule(20) \}
\{ AnswerFormatHelp("points") \}

ANS($answer->cmp() );



In reply to Charles Fortin

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.

$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?
In reply to Alex Jordan

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?
In reply to Davide Cervone

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.
In reply to Alex Jordan

Re: 2 contexts

by Davide Cervone -
I did the same cut-and-paste and it works for me. So I'm going to leave it go for now. If you can give the exact message you got, perhaps I could suggest what might be happening.
In reply to Alex Jordan

Re: 2 contexts

by Charles Fortin -
Great! Works perfectly now. Thank you for writing exactly what was needed, my programming skills in WeBWork are not at this level yet.