## WeBWorK Problems

### Looking for working examples (sagemath cell maybe? ) ### Looking for working examples (sagemath cell maybe? )

by Wai Yan Pong -
Number of replies: 1
I am trying to make a problem like:

Give an example of a subset of {a,b,c,d,e,f,g,h,i,j} of size 5.

Would using SAGE as the checker be a good idea? Can I find a working example for this?

Thanks In reply to Wai Yan Pong

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

by Alex Jordan -

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

https://webwork.maa.org/wiki/Set_(MathObject_Class)
https://webwork.maa.org/wiki/Introduction_to_Contexts

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.

https://webwork.maa.org/wiki/Introduction_to_Contexts#Constants

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: https://webwork.maa.org/wiki/Set_(MathObject_Class)#Methods 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)
if (scalar ($student->value) == 5) {...} I think you could just do: if ($student->value == 5) {...}