Formula Question - Algebraic Answer Type - Partial Grading

Formula Question - Algebraic Answer Type - Partial Grading

by Courtney Boschmann -
Number of replies: 1

Hello all, 

I'm writing a Formula question (with Algebraic answer type) for a test and having some issues with the Partial Grading variables. 

I want students to be able to input an Algebraic formula, so I've selected "Algebraic Answer Type", however this means I will be comparing strings in my Grading Variables and I don't know how to do this! 

  • Ideally, I'd be able to parse the student response string and compare it to chunks of the correct answer string. In short, I'm looking for some sort of string function package to work with. 
  • Alternatively, if there is a better way to do this question (integrated mathematics packages, etc) I'd be happy to try it out, too!

 I've attached my question here. Thanks in advance!

-Courtney

Average of ratings: -
In reply to Courtney Boschmann

Re: Formula Question - Algebraic Answer Type - Partial Grading

by Dominique Bauer -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers
Hello Courtney,

...parse the student response string and compare it to chunks of the correct answer string.
Probably possible, but I'm not quite there yet.

As it stands, I don't think you can use Grading variables with the Algebraic formula answer type. As you say, we need string functions.

Let's add a strcompare() function similar to the PHP strcmp() function, i.e. place the following code in the "variables.php" file, say under the small "case 'join':" code block:

case 'strcompare':
    if (!($sz >= 2 && $types[0] == 's'))  break;
    if (is_string($values[0]) && is_string($values[1])) {
        $this->replace_middle($vstack, $expression, $l, $r, 'n', strcmp($values[0],$values[1]));
    }
return true;
and let's try the following simple example:

Target answer:                 a+b (1 pt)
Answer also accepted:    a-b (0.5 pt)

Grading variables
answer1 = "a+b";
compare1 = strcompare (_0, answer1);
criterion1 = compare1 == 0;
answer2 = "a-b";
compare2 = strcompare (_0, answer2);
criterion2 = compare2 == 0;

Grading criterion
criterion1 + 0.5 * criterion2

The good news is that it works. However, this is certainly not enough. As you mentioned, we would need a string functions package, which contains more string functions than the few that are currently available.  I will try to add string functions in future versions of the Formulas question.