Skip to content

Commit 698ca88

Browse files
authored
Merge pull request #1033 from gajennings/bugfix
Bugfix
2 parents 18516ad + 521b133 commit 698ca88

File tree

1 file changed

+15
-63
lines changed

1 file changed

+15
-63
lines changed

OpenProblemLibrary/Rochester/setSeries6CompTests/ur_sr_6_10a.pg

Lines changed: 15 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -35,85 +35,36 @@ DOCUMENT(); # This should be the first executable line in the problem.
3535
loadMacros(
3636
"PGstandard.pl",
3737
"PGchoicemacros.pl",
38+
"PGgraders.pl",
3839
"PGcourse.pl"
3940
);
4041

4142
################################################################
4243
# We need a special problem grader on this problem, since we
4344
# want the student to get full credit for all six answers correct,
4445
# 50% credit for five correct, and 0% for four or fewer correct.
45-
# To change this scheme, look through the following mess of code
46-
# for the place where the variable $numright appears, and change
47-
# that part.
48-
# Also change the long line beginning "msg ==>", to show what will
49-
# appear on the screen for the student.
50-
#
51-
# To look at the problem itself, look for the boxed comment below
52-
# announcing the problem itself.
46+
# To change this scheme, look for the lines
47+
# $ENV{'grader_numright'}
48+
# $ENV{'grader_scores'}
49+
# $ENV{'grader_message'}
50+
# and follow the instructions for custom_problem_grader_fluid
51+
# in ../webwork2/pg/macros/PGgraders.pl
5352
################################################################
5453

55-
sub custom_problem_grader {
56-
my $evaluated_answers = shift;
57-
my $problem_state = shift;
58-
my %form_options = @_;
59-
60-
# initial setup of the answer
61-
my $total = 0;
62-
my $problem_result = {
63-
score => 0,
64-
errors => '',
65-
type => 'custom_problem_grader',
66-
msg => 'To get full credit, all answers must be correct. Having all but one correct is worth 50%. Two or more incorrect answers gives a score of 0%.',
67-
};
68-
69-
# Return unless answers have been submitted
70-
return($problem_result, $problem_state) unless ($form_options{answers_submitted} == 1);
71-
72-
# Answers have been submitted -- process them.
73-
74-
########################################################
75-
# Here's where we compute the score. The variable #
76-
# $numright is the number of correct answers. #
77-
########################################################
78-
my $numright=0;
79-
80-
foreach my $key (keys %$evaluated_answers) {
81-
# summing the scores is identical to checking each one is correct
82-
$numright += $evaluated_answers->{$key}{score};
83-
}
84-
85-
if ($numright == 6) {
86-
$problem_result->{msg} = 'This attempt scored 100%. Nice work.';
87-
$total = 1;
88-
} elsif ($numright == 5) {
89-
$problem_result->{msg} = 'This attempt scored 50%. You must answer each part correctly for full credit.';
90-
$total = 0.5;
91-
} else {
92-
# the default message will suffice
93-
$total = 0;
94-
}
95-
96-
$problem_result->{score} = $total;
97-
98-
# increase recorded score if the current score is greater.
99-
$problem_state->{recorded_score} = $problem_result->{score}
100-
if $problem_result->{score} > $problem_state->{recorded_score};
101-
102-
$problem_state{num_of_correct_ans}++ if $total == 1;
103-
$problem_state{num_of_incorrect_ans}++ if $total < 1;
104-
return ($problem_result, $problem_state);
105-
}
106-
10754
################################################################
10855
# Now, on with the problem itself.
10956
################################################################
11057

111-
11258
TEXT(beginproblem());
113-
$showPartialCorrectAnswers = 0;
11459

115-
install_problem_grader(~~&custom_problem_grader);
60+
$showPartialCorrectAnswers = 1;
11661

62+
install_problem_grader(~~&custom_problem_grader_fluid);
63+
$ENV{'grader_numright'} = [5,6];
64+
$ENV{'grader_scores'} = [0.5,1];
65+
$ENV{'grader_message'} = "You can earn " .
66+
"50% partial credit for 5 correct answers, " .
67+
"100% credit 6 correct answers.";
11768

11869
$a0 = random(2,7,1);
11970
$b0 = random(2,7,1);
@@ -173,6 +124,7 @@ $ans[4] = join " ",$ALPHABET[3];
173124
$ans[5] = join " ",$ALPHABET[0];
174125
$ans[6] = join " ",$ALPHABET[2];
175126
$ans[7] = join " ",$ALPHABET[1];
127+
176128
ANS(str_cmp([@ans[@slice]], filters=>["remove_whitespace","ignore_order","ignore_case"]));
177129

178130
ENDDOCUMENT(); # This should be the last executable line in the problem.

0 commit comments

Comments
 (0)