WeBWorK Problems

don't understand list answer

don't understand list answer

by Joseph Pedersen -
Number of replies: 4
I don't know why this question won't accept (1,2) as the correct answer:

DOCUMENT();

loadMacros('PGstandard.pl', 'PGML.pl',"MathObjects.pl",

"parserFunction.pl", 'PGtikz.pl', 'niceTables.pl', 'PGcourse.pl');

$showPartialCorrectAnswers = 1;

@mylist = (1,2);

$ans1 = List(@mylist);

BEGIN_PGML

The answer is an empty list

[` X = `][_]{$ans1->cmp(requireParenMatch => 0)} 

END_PGML

ENDDOCUMENT();

The error message that I get is:
Your answer isn't a number (it looks like a list of numbers)

Which doesn't make sense to me because the answer SHOULD be a list of numbers.

This is a minimal reproducible example. My actual homework is much longer and I originally thought the problem I was having was because the answer is a list of lists, and some of the lists are empty. But in trying to make a min reprex for that, I realized that I just don't understand the list questions at all.

In reply to Joseph Pedersen

Re: don't understand list answer

by Glenn Rice -

You need to also add the "implicitList => 0" flag.  Otherwise it will turn (1, 2) into the list containing the single entry (1, 2), i.e., ((1,2)).  Which is why it says your answer isn't a number, it looks like a list.  It is seeing that the first entry of the list is a a list, and it is looking for a number.

Note that it will also accept [1, 2] as correct.

In reply to Glenn Rice

Re: don't understand list answer

by Joseph Pedersen -
I'll try that, thank you.  I'm actually having a similar error on a different problem, but with sets (picture below).

I make the answer a Set MathObject from an array:

@from3 = ();
for $j (0..12) {
    if ( $MT->element($ao[3]+1,$j+1) > 0 ) {
        push(@from3, $j);
    }
}
$ans3 = Set(@from3);

And then the answer in PGML using:

The states accessible from [`[$ao[3]] `] are: [_]{$ans3} 

I tried changing it to:

The states accessible from [`[$ao[3]] `] are: [_]{$ans3->cmp(implicitList => 0)} 

But it still is not recognizing singletons as sets.  Can you tell from that what I'm doing wrong?  Or would you need to see the whole code?

Attachment webwork_singleton_set_error.png
In reply to Joseph Pedersen

Re: don't understand list answer

by Joseph Pedersen -
So I found that the following fixes the problem for Lists, but NOT for Sets:
The states accessible from [`[$ao[3]] `] are: [_]{$ans3->cmp(requireParenMatch => 0, implicitList => 0)} 
However, even with:
requireParenMatch => 0, 
...answers are still required to have parentheses instead of curly brackets for Lists with MORE than one item (or empty lists), but it accepts curly brackets in the answer for lists with one item.

So, adding the following solved my problem:
if ((scalar @from3) > 1) {
    $ans3 = Set(@from3);
} else {
    $ans3 = List(@from3);
}

Now, if the answer is a set with only one item, the correct answer is a List MathObject, but students can enter it as a Set (i.e. surrounded by curly brackets) and the answer is marked correct.