WeBWorK Problems

a problem with previewing answer

a problem with previewing answer

by Dave Meng -
Number of replies: 2
Hi,

We are using an old problem from the problem library. It is
Rochester/setLimitsRates2Limits/ur_lr_2_11.pg

When students submitted their answers, they'll encounter a warning sign. With further investigation, I found that the second part of the answer (a string) won't show if I preview my answer even though the problem still accepts it. How can I fixed it?

Thanks,

Dave
--------------------------------------------------------------------------------------------------
Here is the warning sign:

The evaluated answer is not an answer hash HASH(0xbe8b7698): |HASH|.

WeBWorK Warnings

WeBWorK has encountered warnings while processing your request. If this occured when viewing a problem, it was likely caused by an error or ambiguity in that problem. Otherwise, it may indicate a problem with the WeBWorK system itself. If you are a student, report these warnings to your professor to have them corrected. If you are a professor, please consult the warning output below for more information.

Warning messages

  • HASH(0xbe8b7698) is not an answerHash in queue evaluator
  • HASH(0xbe8b7698) is not an answerHash in queue post_filter


I am also posting the code here in case anyone can not find the problem.
-----------------------------------------------------------------------------------------------
#DESCRIPTION
#KEYWORDS('limits', 'sequences', 'squeeze theorem')
# Find limits using the squeeze theorem
#ENDDESCRIPTION

##KEYWORDS('Calculus')
##Tagged by ynw2d

##DBsubject('Calculus')
##DBchapter('Limits and Derivatives')
##DBsection('Calculating Limits Using the Limit Laws')


DOCUMENT(); # This should be the first executable line in the problem.

loadMacros("PG.pl",
"PGbasicmacros.pl",
"PGchoicemacros.pl",
"PGanswermacros.pl",
"PGauxiliaryFunctions.pl");


$a = random(2,4,1);
$b = random(6,8,1);
$c = random(-6,-2,1);
# coefficients of quadratic x^2 + a1x + a2 passing through c at a
$a1 = $b-$a;
$a2 = -$a*$b+$c;
# coefficients of line b1x +b2 passing through c at a and tangent to quadratic above.
$b1 = $a + $b;
$b2 = -$a*($a +$b) + $c;

TEXT(beginproblem());
$showPartialCorrectAnswers=1;

BEGIN_TEXT
If \[ ${b1}x +$b2 \le f(x) \le x^2 + ${a1}x + $a2 \] determine
\(\displaystyle \lim_{x\to $a} f(x) \) = \{ans_rule(20) \}
$PAR

What theorem did you use to arrive at your answer? $BR
\{ ans_rule(50) \}

END_TEXT


$ans_eval = sub { my $in = shift;
$in = lc($in);
my $score;
if ( $in =~ /squeeze/ or $in =~ /pinch/ or $in =~/sandwich/) {
$score = 1;
} else {
$score = 0;
}
my $ans_hash = { score => $score,
correct_ans => "The Squeeze theorem",
student_ans => $in,
ans_message => ($score) ? '' : "Hint: Look thorugh the end of section 2.3",
};
$ans_hash;
};

ANS(num_cmp($c), $ans_eval);
ENDDOCUMENT(); # This should be the last executable line in the problem.
-----------------------------------------------------------------------------------------------------------------
In reply to Dave Meng

Re: a problem with previewing answer

by Andy Fuchs -
We once-upon-a-time patched the version of the problem you're using via the following:

##################
$ans_eval = sub { my $in = shift;
$in = lc($in);
my $score;
if ( $in =~ /squeeze/ or $in =~ /pinch/ or $in =~/sandwich/\
) {
$score = 1;
} else {
$score = 0;
}

my $ans_hash = new AnswerHash( score => $score,
correct_ans => "The Squeeze theorem",
student_ans => $in,
ans_message => ($score) ? '' : "Hint: \
Look thorugh the end of section 2.6",
);
$ans_hash;
};
##################

Best, though, is first to try the newest source for this 'Library/Rochester/setLimitsRates2Limits/ur_lr_2_11_mo.pg', which looks as follows:

#DESCRIPTION
# Find limits using the squeeze theorem
#ENDDESCRIPTION

## DBsubject(Calculus - single variable)
## DBchapter(Limits and continuity)
## DBsection(Squeeze theorem)
## Date(6/3/2002)
## MLT(limits_squeeze_linear_and_quadratic)
## Level(3)
## MO(1)
## TitleText1('Calculus: Early Transcendentals')
## AuthorText1('Stewart')
## EditionText1('6')
## Section1('2.3')
## Problem1('34')
## KEYWORDS('limits', 'sequences', 'squeeze theorem','Calculus')
## MO(1)-TF-12/18/2014

DOCUMENT(); # This should be the first executable line in the problem.


loadMacros(
"PGstandard.pl", # Standard macros for PG language
"MathObjects.pl",
"PGchoicemacros.pl",
#"source.pl", # used to display problem source button
"PGcourse.pl", # Customization file for the course
);

TEXT(beginproblem());
$showPartialCorrectAnswers = 1;

##############################################################
#
# Setup
#
#
Context("Numeric");


$a = random(2,4,1);
$b = random(6,8,1);
$c = random(-6,-2,1);
# coefficients of quadratic x^2 + a1x + a2 passing through c at a
$a1 = $b-$a;
$a2 = -$a*$b+$c;
# coefficients of line b1x +b2 passing through c at a and tangent to quadratic above.
$b1 = $a + $b;
$b2 = -$a*($a +$b) + $c;

$lhs = Compute("${b1} x +$b2 ")->reduce;
$rhs = Compute("x^2 + ${a1} x + $a2")->reduce;

$ans = Real($c);


Context()->strings->add("The Squeeze theorem"=>{},squeeze=>{alias=>"The Squeeze Theorem"},
pinch=>{alias=>"The Squeeze Theorem"},sandwich=>{alias=>"The Squeeze Theorem"});


Context()->texStrings;
BEGIN_TEXT
If \[ $lhs \le f(x) \le $rhs \] determine
\(\displaystyle \lim_{x\to $a} f(x) \) = \{ans_rule(20) \}
$PAR

What theorem did you use to arrive at your answer? $BR
\{ ans_rule(50) \}


END_TEXT
Context()->normalStrings;

ANS($ans->cmp);

# there doesn't seem to be an easy way to handle short phrase
# answers using MathObjects -- since
# the parser will try to restrict the answer to words which
# are specically allowed in the context.
# create a special answer evaluator.

$ans_eval = new AnswerEvaluator();
$ans_eval->install_evaluator( sub {
my $rh_ans = shift;
my $student_answer = $rh_ans->{student_ans};
$student_answer = lc($student_answer);
my $score = ( $student_answer =~ /squeeze/ or
$student_answer =~ /pinch/ or
$student_answer =~ /police/ or
$student_answer =~ /sandwich/ );
$rh_ans->{score} = $score; # correct if one of these words is mentioned in the answer.
$rh_ans->{correct_ans} = "The squeeze theorem";
$rh_ans->{ans_message} = "The functions limit is squeezed between values that are easier to calculate.";
return $rh_ans;
}
);

ANS($ans_eval);

;
ENDDOCUMENT();

In reply to Andy Fuchs

Re: a problem with previewing answer

by Dave Meng -
Hi Andy,

Thanks so much for your quick help. I tried your patch. It worked. I am going to switch to the new version you pointed out. I actually like the patched version better. If a student entered a wrong answer or no answer, he/she will get a hint. If he/she entered a correct one, every thing is fine. The new version will show a message no matter whether or not a student entered a correct answer.

Thanks again,

Dave