WeBWorK Main Forum

Answer consisting of a list of ordered pairs with letters as the entries

Answer consisting of a list of ordered pairs with letters as the entries

by James Mc Laughlin -
Number of replies: 2
How do I set things up so that WebWork will accept a list of ordered pairs where the entries are letters as an answer?

For example, students would type something like
(B,E),(B,F),(B,H)
into the answer box as the correct answer.

The order of the ordered pairs would not matter, in that (B,F),(B,E),(B,H) would also be a correct answer, but the order inside the ordered pairs need to right, so that (E,B),(B,F),(B,H) would be a wrong answer.

I am a beginner at writing WebWork problems, so it would also be helpful if you could let me know if I need to load any special macros, or need to make any special content statements.

Thanks,

Jimmy Mc Laughlin
In reply to James Mc Laughlin

Re: Answer consisting of a list of ordered pairs with letters as the entries

by Davide Cervone -
At the top of your problem, after the
TEXT(beginproblem());
add
Context("Numeric");
Context->strings->are(
  B => {caseSensitive => 1},
  E => {caseSensitive => 1},
  F => {caseSensitive => 1},
  H => {caseSensitive => 1},
)
and include any other letters that you need (or that the students are likely to type). Then
$ans = Compute("(B,E),(B,F),(B,H)");

BEGIN_TEXT
Your list of pairs is: \{$ans->ans_rule(15)\}
END_TEXT

ANS($ans->cmp);
should do what you want.
In reply to Davide Cervone

Re: Answer consisting of a list of ordered pairs with letters as the entries

by James Mc Laughlin -
Thanks a lot.

With a little bit of tinkering I was able to get that to mesh with what I had.