rvf has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Efficient Rating of Test Answers
by enoch (Chaplain) on Aug 13, 2001 at 23:23 UTC | |
by Hofmator (Curate) on Aug 14, 2001 at 13:24 UTC | |
|
(jeffa) Re: Efficient Rating of Test Answers
by jeffa (Bishop) on Aug 13, 2001 at 23:24 UTC | |
by Hofmator (Curate) on Aug 14, 2001 at 13:37 UTC | |
by jeffa (Bishop) on Aug 14, 2001 at 19:16 UTC | |
|
Re: Efficient Rating of Test Answers
by John M. Dlugosz (Monsignor) on Aug 13, 2001 at 23:26 UTC | |
|
Re: Efficient Rating of Test Answers
by VSarkiss (Monsignor) on Aug 13, 2001 at 23:37 UTC | |
|
Re: Efficient Rating of Test Answers
by runrig (Abbot) on Aug 14, 2001 at 01:18 UTC | |
|
THANK YOU!
by rvf (Novice) on Aug 14, 2001 at 22:46 UTC |