WeBWorK Main Forum

How to let PGML accept multiple alternative string answers for a single question

How to let PGML accept multiple alternative string answers for a single question

by Yuncong Chen -
Number of replies: 1
Hi, 

I am wondering if it is possible for PGML to accept multiple alternative answers for a single question. The answers may not compute to the same value. For example, when two strings represent cycle notations of permutation, "(123)(4)" and "(123)" are both acceptable answers.

Thanks,
Yuncong
In reply to Yuncong Chen

Re: How to let PGML accept multiple alternative string answers for a single question

by Davide Cervone -
You can use the OneOf MathObject available from the parserOneOf.pl file (see its documentation for details). For example:
    loadMacros(
      "PGML.pl",
      "parerOneOf.pl",
    );
    
    BEGIN_PGML
    Your answer is: [__________]{OneOf("x+1","x-1")}
    END_PGML
would allow the student to answer either x+1 or x-1 (or 1+x, or -(1-x), or anything equivalent to one of those).

On the other hand, I've just posted an answer to another question that includes a context for permutations, in in that context, both of your answers would be marked correct automatically. So you might be better off using that context directly.

In your can, you might also need to accept "(312)", "(231)", "(312)(4)", "(231)(4)", "(4)(123)", etc., unless you are forcing the students to enter the permutation in a canonical form. The context that I created allows you some control over whether the student must use disjoint cycles, or use the canonical form.