WeBWorK Problems

list of letters as answer

list of letters as answer

by Carl Yao -
Number of replies: 1
Hello:

I'm trying to ask WeBWorK to accept a list of strings as answers, with no luck. For example, I want a,b,c to be the answer, but I need the ability to combine two lists, like the following code.

It generates and error. Is there a way to do this?

Thanks!

Carl Yao


Context("Numeric");
Context()->variables->add(a=>'Real',b=>'Real',c=>'Real');

$d = Compute("a");
$l1 = List($d);

$e = Compute("b","c");
$l2 = List($e);

$l3 = $l1+$l2;


BEGIN_PGML

[___________]{$l3}

END_PGML
In reply to Carl Yao

Re: list of letters as answer

by Ryan Maccombs -
See http://webwork.maa.org/moodle/mod/forum/discuss.php?d=3497

In particular, I like

"

Alternatively, you might want to use the contextString.pl context, which allows only string answers, and only the ones your define. Here is one approach:

loadMacros("contextString.pl");

Context("String");
Context()->operators->redefine(',', using=>','); # allow lists of strings
Context()->strings->add(
"BC" => {caseSensitive=>1}, "CB" => {alias => "BC", caseSensitive=>1},
"AD" => {caseSensitive=>1}, "DA" => {alias => "AD", caseSensitive=>1},
);

BEGIN_PGML
[________]{"BC,AD"}
END_PGML

"