Partial credit for answer that is close but exact.

17 views
Skip to first unread message

David Wishart

unread,
May 1, 2025, 11:29:01 AMMay 1
to Numbas Users
I'd like to award a partial credit for answers that are not exact but within an allowable range. I already have a custom marking algorithm (this) that works fine if the answer has one or more decimal places required but it falls down when it's a whole number.

I've made  an example question here.

Basically part a) works fine as there is at least one decimal place required. For example an answer to 1dp would get partial credit if it was within +/-0.5, within +/-0.05 if 2 dp etc.

Part b) shows what happens when I have a whole number answer, what I'd like to happen is to have partial credit within +/-5. For example, If the exact answer was 42 then 42 would get full marks with 37~41 and 43~48 getting partial credit. Much as I can see that the algorithm is calculating the margins correctly nothing is being applied. 

It looks like if once the precision is set to 0 then my custom 'numberInRange' algorithm isn't being run. I've looked at the standard algorithm and don't see anything in 'mark' that would do this. I also see there is a test for isInteger but don't see anything being done with this value.



Christian Lawson-Perfect

unread,
Jun 5, 2025, 3:37:54 AMJun 5
to numbas...@googlegroups.com
There were two errors in your marking algorithm.
The first is just that you got a closing bracket in the wrong place in the "correctPrecision" note, so the 'if' function only had one argument. Anyway, you don't need the 'if', because `if(condition, true, false)` is equivalent to `condition` on its own.

The second error was that I think you assumed that the 'and' operation is lazy, which it is in most languages, but not in Numbas. In the switch statement in "numberInRange", you had `settings["precisionType"]="sigfig" and studentNumber=siground(minvalue, settings["precision"]), correct(),`

When the precision is set to 0 decimal places, both parts of that condition are evaluated, so it tries to calculate `siground(minvalue, 0)`, which throws an error because you can't have 0 sig figs.

A way round this is to notice that whatever rounding method you use, you want to compare the student's number with the expected correct number. So compute the correct number in a separate note, then use that in the numberInRange note to compare with the student's number.

I've made a copy of your question at https://numbas.mathcentre.ac.uk/question/175987/christian-s-copy-of-answer-margin/ and change part b's marking algorithm to apply these fixes.

--
You received this message because you are subscribed to the Google Groups "Numbas Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to numbas-users...@googlegroups.com.
To view this discussion, visit https://groups.google.com/d/msgid/numbas-users/45ff7404-7375-461c-b87e-16d58622c235n%40googlegroups.com.

David Wishart

unread,
Jun 5, 2025, 12:31:24 PMJun 5
to Numbas Users
Thanks Christian, that works perfectly now.
Reply all
Reply to author
Forward
0 new messages