Last year, Zig Fiedorowicz offered some code to allow one to examine a
student's answers before deciding how to process them. For example, a
solution to a differential equation may be of the form c_1 f_1 + c_2
f_2, and the students are asked to enter functions f_1 and f_2. Since
no order was specified to list the functions f_1 and f_2, you have to
do a little detective work before testing their answers for
correctness.
Below is some parred down code which will function on WeBWork 1.6, but
which fails under WeBWorK 1.7.
The reason it fails appears to be due to a change in num_cmp.
Under WW1.6, the statement
($ans_eval1) = num_cmp(exp(2 * 1));
would produce the value "CODE(0x8967770)" for $ans_eval1
Under WW 1.7, the same statement produces
"AnswerEvaluator=HASH(0x8a7d500)"
This explains why the code below fails. Perhaps someone can suggest a
way around this difficulty. I do not know how to extract any
information from this answer evaluator. I have stared at the "Answer
hash datatype specification", but haven't a clue how to connect it to
named answers.
Thanks in advance.
Tom Shemanske DOCUMENT(); loadMacros(PG.pl, PGbasicmacros.pl, PGchoicemacros.pl, PGanswermacros.pl, PGauxiliaryFunctions.pl, );
TEXT(beginproblem());
BEGIN_TEXT $BR Enter the functions ( e^{2t} ) and (e^{3t}) in the blanks below
$BR
(f_1(t) = ) {NAMED_ANS_RULE(first_fcn,25)} and (f_2(t) = ) {NAMED_ANS_RULE(second_fcn,25)}
$PAR END_TEXT
## Grab the first answer entered by student $firstAnswer = $inputs_ref->{first_fcn};
## An alternate means of grabbing the function #$firstAnswer = ${$main::inputs_ref}{first_fcn} if defined(${$main::inputs_ref}{first_fcn});
## Make sure it is defined $firstAnswer = '' unless defined($firstAnswer);
## Globally substitute (1) for t in $firstAnswer $firstAnswer =~ s/t/(1)/g;
## Answer evaluator for the first function at t = 1 ($ans_eval1) = num_cmp(exp(2 * 1));
#My mucking around trying to fix things #$rh_ans_hash = new AnswerHash;
## Check first answer against "correct" first answer $rh_ans_hash = &$ans_eval1($firstAnswer);
## Check answers accordingly if ( $rh_ans_hash->{score} == 1 ) { NAMED_ANS( first_fcn, fun_cmp("exp(2*t)", vars=>['t']) ); NAMED_ANS( second_fcn, fun_cmp("exp(3*t)", vars=>['t']) ); } else { NAMED_ANS( first_fcn, fun_cmp("exp(3*t)", vars=>['t']) ); NAMED_ANS( second_fcn, fun_cmp("exp(2*t)", vars=>['t']) ); }
ENDDOCUMENT();
The error one gets is
"Not a CODE reference at (eval 54) line 42."
in reference to
($ans_eval1) = num_cmp(exp(2 * 1));
which makes sense since $ans_eval1 does not evaluate to CODE but to
Answer_Evaluator as mentioned above.
<| Post or View Comments |>
|