WeBWorK Problems

Error created upon applying a weighted grader format?

Error created upon applying a weighted grader format?

by tim Payer -
Number of replies: 2

Greetings,

 

I just recently added a weighted grader format to this problem and for some reason I am generating the following error statement:

 

ERRORS from evaluating PG file:
 Can't call method "cmp" without a package or object reference at line 184 of (eval 14815)

 

Can you determine what my glitch is here? I do not see anything on line 184 that would be a problem.

 

Thanks, Tim

 

        Problem2

ERROR caught by Translator while processing problem file:Payer/S109/HW_4/income_longevity.pg

****************

ERRORS from evaluating PG file: 
 Can't call method "cmp" without a package or object reference at line 184 of (eval 19528)



 

****************

------Input Read

1              ##DESCRIPTION

2              ##   Applying the Rules of addition in probability given table data.

3              ##  Emphasis on notation as well as numeric calculation.

4              ##  Options for randomizing table data for algorithmic solutions.

5              ##ENDDESCRIPTION

6              

7              

8              ## DBsubject(Probability)

9              ## DBchapter(Random variables)

10             ## DBsection(Expectation)

11             ## Institution(HSU)

12             ## Beginning Statitstics(Tim Payer)

13             ## KEYWORDS('probability','rules of addition','notation')

14             

15             DOCUMENT();        # This should be the first executable line in the problem.

16             

17             loadMacros(

18             "PGstandard.pl",

19             "PGunion.pl",

20             "MathObjects.pl",

21             "PGchoicemacros.pl",

22             "PGanswermacros.pl",

23             "PGauxiliaryFunctions.pl",

24             "PGasu.pl",

25             "PGML.pl",

26             "parserPopUp.pl",

27             "weightedGrader.pl"

28             );

29             

30             install_weighted_grader();

31             

32             TEXT(beginproblem());

33             

34             ## If you would rather not have algorithmic solutions with randomized table data:

35             ## You can "switch" off the randomization by un-commenting the declarations below  

36             ## and then comment out the equivalent declarations that have randomization

37             ## in their declarations.

38             

39             # $r[4] = 15;

40             # $u[4] = 150;

41             # $m[4] = 200;

42             # $l[0] = 205;

43             # $p[0] = 40;

44             

45             Context("Numeric");

46             Context()->flags->set(

47               tolerance => 0.0001,

48               tolType => "absolute",

49             );

50             

51             

52             @x=( "89-95","86-88", "81-85", "77-80", "75-76");

53             $r[4]= random(12, 18,1);

54             $r[3]= $r[4]*4 -1;

55             $r[2]= $r[4]*10 +3;

56             $r[1]= $r[4]*15 -5;

57             $r[0]= $r[4]*20 -14;

58             $rsum = $r[4]+$r[3]+$r[2]+$r[1]+$r[0];

59             

60             $u[4]= random(121, 131,1);

61             $u[3]= $u[4]*2 +25;

62             $u[2]= $u[4]*4 +3;

63             $u[1]= $u[4]*12 -15;

64             $u[0]= $u[4]*5 -14;

65             $usum = $u[4]+$u[3]+$u[2]+$u[1]+$u[0];

66             

67             $m[4]= random(201, 231,1);

68             $m[3]= $m[4]*4 -14;

69             $m[2]= $m[4]*10 +13;

70             $m[1]= $m[4]*6 -15;

71             $m[0]= $m[4]*3 +14;

72             $msum = $m[4]+$m[3]+$m[2]+$m[1]+$m[0];

73             

74             $l[0]= random(204, 224,1);

75             $l[1]= $l[0]*2 +52;

76             $l[2]= $l[0]*3 +33;

77             $l[3]= $l[0]*10 -5;

78             $l[4]= $l[0]*3 +14;

79             $lsum = $l[4]+$l[3]+$l[2]+$l[1]+$l[0];

80             

81             $p[0]= random(31, 43,1);

82             $p[1]= $p[0]*2 -17;

83             $p[2]= $p[0]*3 +3;

84             $p[3]= $p[0]*6 -15;

85             $p[4]= $p[0]*7 +24;

86             $psum = $p[4]+$p[3]+$p[2]+$p[1]+$p[0];

87             

88             $grand = $psum +$lsum +$msum +$usum +$rsum;

89             

90             $col0sum = $r[0]+$u[0]+$m[0]+$l[0]+$p[0];

91             $col1sum = $r[1]+$u[1]+$m[1]+$l[1]+$p[1];

92             $col2sum = $r[2]+$u[2]+$m[2]+$l[2]+$p[2];

93             $col3sum = $r[3]+$u[3]+$m[3]+$l[3]+$p[3];

94             $col4sum = $r[4]+$u[4]+$m[4]+$l[4]+$p[4];

95             

96             #$c1 = "P(B ~~x{2229} F)";

97             #$c2 = "P(B ~~x{222A} F)";

98             #$c3 = "P(B ~~x{2A2F} F)";

99             

100            $popup1 = PopUp(

101            ["probability notation", "P(86-88)", "P(A)", "P(B)", "P(C)", "P(D)","P(E)"], "P(B)");

102            $ans1 =$col1sum/$grand;

103            

104            $popup2 = PopUp(

105            ["probability notation", "P(B U F)",  "P(BF)", "P(B n F)", "P(B + F)", "P(B x F)"], "P(B n F)");

106            $ans2 =$p[1]/$grand;

107            

108            #Unicode errors due to non acceptance of: "P(B ~~x{2229} F)"

109            # Apparently the unicode wont work here?  "~~x{2229}" wont render

110            # I will replace the "n" with intersection symbols once the proper code is found.

111            # And I still need to weight the responses with points.

112            

113            $popup3 = PopUp(

114            ["probability notation", "P(R U L)", "P(RL)", "P(R n L)", "P(R + L)", "P(R x L)"], "P(R n L)");

115            $ans3 =0;

116            

117            $popup4 = PopUp(

118            ["probability notation", "P(R U L)", "P(RL)", "P(R n L)", "P(R + L)", "P(R x L)"], "P(R U L)");

119            $ans4 =($rsum+$lsum)/$grand;

120            

121            $popup5 = PopUp(

122            ["probability notation", "P(F n E)", "P(FE)", "P(F U E)", "P(F + E)", "P(F x E)"], "P(F U E)");

123            $ans5 =Compute("($psum+$col4sum-$p[4])/$grand");

124            

125            

126            

127            BEGIN_TEXT

128            $BR

129            

130            4.2)  Recent census data supports the case that life expectancy is correlated with one's income bracket. Given a small town with a population of \($grand\) individuals has a distribution of life expectancy loosely based on the recent census, determine the following probabilities with fourth decimal accuracy. $BR

131            $PAR

132            $BLEFT

133            \{begintable(6)\}

134            \{row("Expectancy in years", @x, "Row Sum")\}

135            \{row("Rich", $r[0], $r[1],$r[2],$r[3],$r[4],$rsum)\}

136            \{row("Upper Middle Class", $u[0], $u[1],$u[2],$u[3],$u[4],$usum)\}

137            \{row(" Middle Class", $m[0], $m[1],$m[2],$m[3],$m[4],$msum)\}

138            \{row("Lower Middle Class", $l[0], $l[1],$l[2],$l[3],$l[4],$lsum)\}

139            \{row("Poor", $p[0], $p[1],$p[2],$p[3],$p[4],$psum)\}

140            \{row("Column Sum", $col0sum, $col1sum,$col2sum,$col3sum,$col4sum,$grand)\}

141            \{endtable()\}

142            $ELEFT

143            

144            $PAR

145            Use the the following event variable declarations within probability notation to find the associated probabilities with fourth decimal accuracy. 

146            $PAR

147            END_TEXT

148            

149            BEGIN_PGML

150            

151            [`A`] = Event that an individual of the town has a life expectancy of 89-95 years.  

152            [`B`] = Event that an individual of the town has a life expectancy of 86-88 years.  

153            [`C`] = Event that an individual of the town has a life expectancy of 81-85 years.  

154            [`D`] = Event that an individual of the town has a life expectancy of 77-80 years.  

155            [`E`] = Event that an individual of the town has a life expectancy of 75-79 years.  

156            [`R`] = Event that an individual of the town is rich.  

157            [`S`] = Event that an individual of the town is of the upper middle class.  

158            [`M`] = Event that an individual of the town is of the middle class.  

159            [`L`] = Event that an individual of the town is of the lower middle class.  

160            [`F`] = Event that an individual of the town is poor.  

161            

162            

163            Note that due to restrictions in the pull down menus used below that the intersection of two events will be indicated with a lower case "n".  

164            This means that [` P(B \, n \, L) = P(B \, \cap \, L)`].  

165              

166            

167            4.2a)  Find the probability of drawing an individual from the town that has a life expectancy of 86-88 years:  

168            

169            [$popup1->menu]* = [____]  

170            

171            

172            4.2b)  Find the probability of drawing an individual from the town that has a life expectancy of 86-88 years and is poor:  

173            

174            [$popup2->menu]* = [____]  

175            

176            4.2c)  Find the probability of drawing an individual from the town that is rich and is of the lower middle class:  

177            

178            [$popup3->menu]* = [____]  

179            

180            4.2d)  Find the probability of drawing an individual from the town that is rich or is of the lower middle class:  

181            

182            [$popup4->menu]* = [____]  

183            

184            4.2e)  Find the probability of drawing an individual from the town that is either poor or has a life expectancy of 75-76 years or both:  

185            

186            [$popup5->menu]* = [____]  

187            

188            END_PGML

189            

190            WEIGHTED_ANS( ($popup1)->cmp, 4 );

191            WEIGHTED_ANS( ($ans1)->cmp, 16 );

192            WEIGHTED_ANS( ($popup2)->cmp, 4 );

193            WEIGHTED_ANS( ($ans2)->cmp, 16 );

194            WEIGHTED_ANS( ($popup3)->cmp, 4 );

195            WEIGHTED_ANS( ($ans3)->cmp, 16);

196            WEIGHTED_ANS( ($popup4)->cmp, 4 );

197            WEIGHTED_ANS( ($ans4)->cmp, 16 );

198            WEIGHTED_ANS( ($popup5)->cmp, 4 );

199            WEIGHTED_ANS( ($ans5)->cmp, 16);

200            

201            

202            

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

 

In reply to tim Payer

Re: Error created upon applying a weighted grader format?

by Paul Pearson -
Hi Tim,

When debugging, it's best to pay close attention to what the error message says and to ask yourself if you have seen this type of error message before.  You have seen this type of error before.  In fact, you posted a similar debugging question very recently and received several answers.  Danny Glin's prior suggestion applies again in this situation.  When you see an error that says 


it means that you applied an answer checker to something that was not a MathObject.  For instance

$answer = random(2,4,1);
ANS( $answer->cmp );

will produce an error message because $answer is a PERL scalar and does not have a method ->cmp defined on it.  Note: $answer above is NOT a MathObject.

If, instead, you use

$a = $random(2,4,1);
$answer = Compute("$a x");
ANS( $answer->cmp );

then the Compute() method from the MathObjects.pl macro converts the string "$a x" into a MathObject.  MathObjects do have a method ->cmp defined on them.  The ->cmp method compares the student answer to the correct answer.  Then, ANS() records the result in WebWork's gradebook.

Best regards,

Paul Pearson
In reply to Paul Pearson

Re: Error created upon applying a weighted grader format?

by tim Payer -
Thank you Paul,

The error statement looked familiar, but I was still at a loss.

I think your detailed explanation will help me understand the gist of the error, and I should know how to proceed in the future.

Many thanks for your efforts to explain this to this newbie...

Tim