WeBWorK Problems

Looking for working examples (sagemath cell maybe? )

Re: Looking for working examples (sagemath cell maybe? )

by Alex Jordan -
Number of replies: 0

Here is an outline that I would try. First, use a context that can make Set MathObjects. The Interval context can do this.


Next, make a..j be constants in this context. Give them distinct values that a student would never happen to guess. For example, j might be pi/sqrt(2). Set them to always display as their letter, not as a numerical value.


Now make
$full = Set("{a,b,c,d,e,f,g,h,i,j}");
and make one example answer
$answer = Set("{ab,c,d,e}");

Then build a custom answer checker.


The custom answer checker code should check that the student answer is a subset of $full, and that it has five elements. You could use the "contains" method or the "isSubsetOf" method here:


And you need to check the student answer has five elements. I'm guessing that if $student is a Set object, then $student->value will be an array with its entries, and you wnat to access the length of that array. One explicit way to do that is using :
scalar ($student->value)
as in:
if (scalar ($student->value) == 5) {...}

I think you could just do:
if ($student->value == 5) {...}