Answers up to multiplication
Download file: AnswerUpToMultiplication.pg
DOCUMENT();
loadMacros('PGstandard.pl', 'PGML.pl', 'PGcourse.pl');
Preamble
These standard macros need to be loaded.
$ans = Compute('(x + 1)(x - 2)')->cmp(
checker => sub {
my ($correct, $student, $self) = @_;
return 0 if $student == 0;
my $context = Context()->copy;
$context->flags->set(no_parameters => 0);
$context->variables->add('C0' => 'Parameter');
my $c0 = Formula($context, 'C0');
$student = Formula($context, $student);
$correct = Formula($context, "$c0 * $correct");
return $correct == $student;
}
);
Setup
The answer checker uses a local context with an adaptive parameter to check if the student answer is a parameter C0 multiple of the correct answer. For more on adaptive parameters, see AdaptiveParameters.
BEGIN_PGML
Find a quadratic equation in terms of the variable
[`x`] with roots [`-1`] and [`2`].
[`y =`] [_]{$ans}{15}
END_PGML
Statement
This is the problem statement in PGML.BEGIN_PGML_SOLUTION Solution explanation goes here. END_PGML_SOLUTION ENDDOCUMENT();
Solution
A solution should be provided here.