WeBWorK Problems

How can I get the answer entered by the student to be the one displayed?

How can I get the answer entered by the student to be the one displayed?

by Paul Seeburger -
Number of replies: 4
How can I get the answer entered by the student to be the one that is displayed as entered when Check or Preview is clicked?

In particular I am using the ImplicitPlane context and the equation the student enters is automatically simplified before it gets displayed at the top of the WebWork problem.  Here's my code:

Context("ImplicitPlane");
Context()->flags->set(showExtraParens=>0);
Context()->variables->are(x=>'Real');
Context()->flags->set(
  reduceConstants=>0, # no decimals
  reduceFunctions=>0, # combine 4+5*2?
  reduceConstantFunctions=>0,
  formatStudentAnswer=>'parsed', # no decimals
);
$ans1 = ImplicitPlane("$a+x=$b*x");

I thought that the formatStudentAnswer=>'parsed' should force the student answer to be displayed as it was entered.

How can I accomplish what I want?

It seems there should be an option for formatStudentAnswer that will display the answer entered as it was really entered.
In reply to Paul Seeburger

Re: How can I get the answer entered by the student to be the one displayed?

by Paul Seeburger -
To clarify my question a little more:

When the student enters "60 + x = 6x" I would like this to be shown in the Preview and also student entered columns when they check (or preview) their answer, nicely typeset, of course.

But what is happening here, because of the object being checked is an ImplicitPlane is that the student answer (both Preview and Entered) is being displayed as "5x = 60".  This kind of thing does not seem to happen with the Formula object for student answers.  How can I force WeBWorK, to keep the same version/form of the equation to display as what the student entered?


The checker (from a problem by PCC) that formats the correct answer correctly, it seems is:

ANS($ans1->cmp(cmp_class => "a linear equation",correct_ans=>"$a+x=$b x",,correct_ans_latex_string=>"$a+x=$b x"));

But this does not help the formatting (extra simplifying done to the student entered answer).
Thanks!
In reply to Paul Seeburger

Re: How can I get the answer entered by the student to be the one displayed?

by Alex Jordan -
This is one of our problems re-worked to use contextTypeset.pl to accomplish this. I have not tested it thoroughly, especially regarding display mode other than MathJax.

The things to take note of are contextTypeset.pl in the loadMacros call, that the implicit plane in question is created using Compute, and the custom answer checker and the parameters passed to it.

# WeBWorK problem written by Carl Yao, 2013
# Portland Community College
#
# Read a word problem. Write an equation and solve for unknown.
# b more than twice a number is c. What is the number?
#
# Last updated: Kling, 7/21/13; Wherry, 7/03/13, Yao, 6/26/13
# ENDDESCRIPTION

## DBsubject('Algebra')
## DBchapter('Basic Algebra')
## DBsection('Algebraic Expressions')
## KEYWORDS('solve','linear','equation','english-to-math','subtract','divide')
## DBCCSS('6.EE.2.a','7.EE.4','A-CED.1','A-REI.3')
## TitleText1('')
## EditionText1('')
## AuthorText1('')
## Section1('')
## Problem1('')
## Author('Alex Jordan, Carl Yao, Chris Hughes')
## Institution('PCC')

##############################################

DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGML.pl",
"parserImplicitPlane.pl",
"PCCmacros.pl",
"contextTypeset.pl",
"PGcourse.pl",
);

##############################################

$a=random(2,9,1);
$m=random(2,5,1);
$ans2=random(5,15,1);
$b=$a+$m*$ans2;

Context("ImplicitPlane");
Context()->flags->set(showExtraParens=>0);
Context()->variables->are(x=>'Real');
Context()->flags->set(reduceConstants=>0);
$ans1 = Compute("$a+$m*x= $b");

if ($m==2) {$w = "twice";}
else {$w = numberWord($m)." times";}



##############################################

TEXT(beginproblem());

BEGIN_PGML

Write an equation for the following situation, and then solve for the unknown. Please use [`x`] as the unknown variable.

[@numberWord($a,capital=>1)@] more than [$w] a number is [@numberWord($b)@]. What is the number?

Your equation is:
[_______________________]

The unknown number is:
[___________]

END_PGML

##############################################

ANS($ans1->cmp(
cmp_class => "a linear equation",
correct_ans=>Parser::Formula(Context("Typeset") , $ans1->{correct_ans})->string,
correct_ans_latex_string=>Parser::Formula(Context("Typeset") , $ans1->{correct_ans})->TeX,
checker => sub {
my ($correct,$student,$ansHash) = @_;
$result = ($correct == $student);
my $context = Context();
Context("Typeset");
$student = Parser::Formula(Context("Typeset"), $ansHash->{original_student_ans});
$ansHash->{preview_text_string} = $student->string;
$ansHash->{preview_latex_string} = $student->TeX;
$ansHash->{student_ans} = $student->string;
Context($context);
return $result
}));

Context("LimitedNumeric");
ANS(Compute($ans2)->cmp);

$s1=$b-$a;

BEGIN_PGML_SOLUTION

Let the unknown number be [`x`]. The equation is:

[``[@Parser::Formula(Context("Typeset") , $ans1->{correct_ans})->TeX@]``]

Next, we solve for [`x`]:

[`
\begin{aligned}
[$a] {}+[$m]x &\;=\; [$b] \\
[$a] {}+[$m]x \mathbf{{} -[$a]} &\;=\; [$b]\mathbf{{} -[$a]} \\
[$m]x &\;=\; [$s1] \\
\frac{[$m]x}{[$m]} &\;=\; \frac{[$s1]}{[$m]} \\
x &\;=\; [$ans2]
\end{aligned}
`]

The unknown number is [`[$ans2]`].

END_PGML_SOLUTION

ENDDOCUMENT();

In reply to Alex Jordan

Re: How can I get the answer entered by the student to be the one displayed?

by Paul Seeburger -
This works for me for the student answer to be displayed as the student entered it.  But for some reason the correct answer is not displaying for this equation when I select to display correct answers.

I tried the following code and it displays "" in a text region for the contents of $str.

$eq2 = ImplicitPlane("x + y = 2(x - y)");
$str = Parser::Formula(Context("Typeset") , $eq2->{correct_ans})->string;

I do have the right macros loaded, I believe:

  "parserImplicitPlane.pl",
  "contextTypeset.pl",

Am I missing something important to get this to work?

Edit:  Now this is strange.  When I changed the first line to use Compute instead of ImplicitPlane, it works.  What is going on here?  Will this cause any other troubles?

Thanks!

Paul
In reply to Paul Seeburger

Re: How can I get the answer entered by the student to be the one displayed?

by Alex Jordan -
In my earlier message in this thread, I noted that you should use Compute to create the ImplicitPlane. Is this the same issue that you bring up in the edit at the end of this last post? By using Compute, there is a memory of the original string used to create the object. If you use ImplicitPlane directly, then it immediately creates the ImplicitPlane's standard form and only holds on to that moving forward.