On the other hand, we still have a lot to cover, and some of the ideas needed, here, are ones we haven't gotten to yet. Most of it will come on Monday, as they involve MathObjects (as Paul's answer suggests).
The main thing you need to know is how to create the MathObject by hand so that you can manipulate its answer checker before passing it to PGML. (So far, we have only learned how to pass PGML a string containing the answer, but there are more advanced techniques). Paul's solution is the right one, though there are several possible variations on it. I give one below.
I also had the same question as Paul did about the formatting of the code. We have not yet learned all there is about formatting in PGML, and there is a means of getting pre-formatted output that would handle code listings a bit better than what you currently have. I include it below, and we will see it on Monday, or perhaps next Monday depending on how much progress we make this week.
Finally, I wondered whether you wanted the students to have to type the parentheses around their list or not (since these aren't part of the output). If you do, then put them in the answer, otherwise leave them off, so the student can just type 10,16,4
without parentheses.
Here is a non-randomized version of the core of your problem, with the formatting adjusted, and an alternative method of getting the answer checker with ordered
set to true.
Context("Numeric"); $L = Compute("10,16,4"); $cmp = $L->cmp(ordered=>1); BEGIN_PGML Predict the output from the following code. If there are multiple outputs, separate them by commas. If the code will produce an error message, type "Error" (without the quotes). : numbers = c(6, 13, 16) : for (x in numbers) { : if (x %% 2 == 1) { : x = x+3 : } : else if (x < 10) { : x = 10 : } : else { : x = x/4 : } : print(x) : } Output = [__________]{$cmp} END_PGMLI will leave the randomization to you to add.
Note that there is an additional item you will need to consider, which is the fact that if the student types Error
, this will produce an error message, not just mark the answer incorrect. So you will need to do a little more in order to allow Error
as a possible answer. We will learn how to do that on Monday, so I'm leaving it as something you can add later.
Context("Point"); $p = Compute("(2,5)"); BEGIN_PGML The ordered pair is [__________]{$p} END_PGMLYou can also create a point as
$p = Point(2,5);