Consider the following basic problem:
"PGstandard.pl", # Standard macros for PG language
#"source.pl", # allows code to be displayed on certain sites.
#"PGcourse.pl", # Customization file for the course
# Print problem number and point value (weight) for the problem
# Show which answers are correct and which ones are incorrect
$showPartialCorrectAnswers = 1;
$pi = Real("pi");
Enter an exact value for :
$sols = $pi;
When the correct answer is displayed to the student, the correct at answer is displayed to the student as 3.14159 instead of pi. Is there a way to code the problem so that 'pi' is displayed? I have been told previously that this correct answer could not currently be shown in typeset mode. However, here the 3.14159 is pretty misleading, since cut and pasting that into WW will not be marked correct.
Thanks for any guidance you can provide,
We're beginning to collect a significant number of wiki pages that can help
with authoring problems. Here are some pointers:
http://webwork.maa.org/wiki/Category:Authors -- top level
http://webwork.maa.org/wiki/Category:Problem_Techniques -- started by Gavin LaRose -- and since it's a wiki you can help add to it :-)
and here is a lab that allows you to test code fragments (the first lab is the most useful at the moment -- the PGML stuff is for the future)
a modification of the example on that page indicates another way to handle the issue you raise. "Compute" like Formula converts strings to objects but with less overhead -- and it maintains a string that it uses by default for the correct answer.
$ans = Compute("pi");
the last line prints out the entire AnswerHash
-- correct_ans is used as the message in responding to students
-- score =1 or 0 is whether or not the answer is correct.
Most importantly this MathObjects calculator allows you to quickly test things out.
Context("LimitedNumeric"); $ans = Compute("pi"); Context()->constants->remove("pi"); $ans= Compute($ans)->with(format=>'%0.12G'); TEXT($ans->with(correct_ans => $ans)->cmp->evaluate("pi")->pretty_print );
might also be of interest -- although there may be a simpler way to accomplish the same thing
Note that $pi = Real("pi"); is redundant, as $pi = pi; is sufficient (since pi is already defined as a function that returns the value of pi from the current context, and that is a real value already).
I'm also not sure why you feel the need to set the value $sol, since ANS($pi->cmp) would work just as well. Indeed, you do not need the $pi variable either, as ANS(pi->cmp) should do it.
Mike may have misunderstood what you are trying to accomplish, since he suggested the use of the LimitedNumeric from which pi has been removed. That would prevent students from entering the answer as "pi" and would force them to use decimals. You seem to want the opposite: they must not use decimals and must enter pi symbolically. For that, you are correct to use the NoDecimals function.
Arnie's solution did what I was expecting: on the "answer" page, where several boxes are shown, "Entered" displays 3.14159, "Answer preview" displays a nicely typeset \pi, and "Correct" displays 'pi' (no quotes).
Davide, your solution did not do what I was expecting --- the "Correct" box still displayed 3.14159 (although of course the problem was graded correctly).
Perhaps I misunderstood your reply? I'm using the Rochester "hosted2" Webwork server, at the moment.
$pi = Real("pi");to
$pi = Compute("pi");works for me. What exactly did you do?
The stuff about using pi directly was only to clarify why $pi = Real("pi") was redundant. It doesn't fix your problem with the correct answer. But using Compute() should.