WeBWorK Problems

Retrieving students' un-evaluated constant expressions from MultiAns

Re: Retrieving students' un-evaluated constant expressions from MultiAns

by Andrew Parker -
Number of replies: 0
Thanks to Geoff for helping me figure this out - I'll leave the fixed result for anyone else who might run into a similar problem:

$ans = MultiAnswer(Formula("$base^($exp)"),Formula("$result"))->with(
   singleResult => 1,
   separator => " = ",
   tex_separator => " = ",
   checker => sub {
      my ($correct,$student,$self) = @_;  # get the parameters
      my ($ansHash1, $ansHash2) = @{$self->{ans}};
      my $lhs = $ansHash1->{student_formula};
      my $rhs = $ansHash2->{student_formula};
      my ($exp,$res) = @{$correct};
      $lhs = Formula("$lhs"); $rhs = Formula("$rhs"); $exp = Formula("$exp");
      return 0 unless (($lhs == $exp) && ($rhs == $res));
      Context()->flags->set(bizarroDiv=>1, bizarroMul=>1, bizarroAdd=>1, bizarroSub=>1, bizarroPow=>1 );
      Value::Error("Your equation is not in exponential form.") unless ((($lhs == $exp || $exp == $lhs) && ($rhs == $res || $res == $rhs)) || (($lhs == $res || $res == $lhs) && ($rhs == $exp || $exp == $rhs)));
      Context()->flags->set(bizarroDiv=>0, bizarroMul=>0, bizarroAdd=>0, bizarroSub=>0, bizarroPow=>0 );
      return 1;
       },
  );

BEGIN_PGML

Rewrite the logarithmic equation in exponential form.

>> [`` \log_[$base]([$result]) = [$exp] ``] <<

[________]{$ans} = [________]{$ans}

END_PGML

ENDDOCUMENT();