WeBWorK Problems

Factorials as a Formula object

Re: Factorials as a Formula object

by Danny Glin -
Number of replies: 0

This question looks like a perfect candidate for DraggableProofs.  When students are asked to enter answers chosen from a fixed list I think it's bad practice to force them to type free-form text.

Since factorial is only defined for nonnegative integers you do need to specify to only evaluate the function at integer values.  I suspect that the reason it wasn't working for you is because you've added the variable n to the context, which leaves any existing variables in the context (i.e. x).  Since there are two variables, if you use 'test_at' you will need to specify pairs of numbers as test points (i.e. values for both n and x).

Here is what you probably want:

Context()->variables->are(n => ['Real', limits=>[1,10], resolution=>1]);

Using "are" instead of "add" removes all other variables from the context.  The remaining arguments specify that the values that n can take on are between 1 and 10, going up by 1, so you will only get integer values.