I have a script that must grade an exam in which there are several correct (and half correct) answers to a question. On this exam, one must match the spectral classification of a star with an image of a star (going by a comparison key). Spectral Classifications are classified by a letter-number combination, like "B1", "K8", and "G5" -- with the numbers ranging 0-9. The possible letters are: O, B, A, F, G, K and M (in order of ascension).
Now on to the code... Here is what I have determined will work to exam and grade each question, but it seems to me that there would be a better way.
sub gradeTest { my $answer, $runningTotal; $runningTotal = 0; $answer = lc(param(ans1)); # For answer 1, G6-G9 is full credit. # G0-G5 and K0-K5 are half credit if ($answer eq "g6" || $answer eq "g7" || $answer eq "g8" || $ans +wer eq "g9") { $runningTotal += 1; } elsif ($answer eq "g0" || $answer eq "g1" || $answer eq "g2" || + $answer eq "g3" || $answer eq "g4" || $answer eq "g5") { $runningTotal += .5; } elsif ($answer eq "k0" || $answer eq "k1" || $answer eq "k2" || + $answer eq "k3" || $answer eq "k4" || $answer eq "k5") { $runningTOtal += .5; } }
There are 12 questions on the test, so you can see that going through this 12 times is not optimal. Also, keep in mind that some answer ranges also span letters as well, like O9-B1, which, at least to me, seems to make condensing this more difficult.
Thanks for any suggestions.
In reply to Efficient Rating of Test Answers by rvf
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |