Difference between revisions of "AnswerHints"

From WeBWorK_wiki
Jump to navigation Jump to search
(8 intermediate revisions by 4 users not shown)
Line 3: Line 3:
 
<!-- Header for these sections -- no modification needed -->
 
<!-- Header for these sections -- no modification needed -->
   
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;">
+
<div style="background-color:#eeeeee;border:black solid 1px;padding:3px;">
This PG code shows how to include two different kinds of answer hints:
+
This PG code shows how to include three different kinds of answer hints:
 
<ul type="square">
 
<ul type="square">
<li>General answer hints that help students get started on a problem and are made available after a student has submitted an answer at least once (a "Show hints" checkbox appears near the "Submit Answers" button).</li>
+
<li>General answer hints that help students get started on a problem and are always available via "Knowls".</li>
<li>Specific, customized answer hints that appear in the answer feedback messages box after a student submits a particular answer that activates a pre-programmed hint.</li>
+
<li>General answer hints that help students get started on a problem and are made available after a student has submitted an answer at least once (a "Show hints" checkbox appears near the "Submit Answers" button) via a <code>BEGIN_HINT / END_HINT</code> block of text.</li>
  +
<li>Specific, customized answer hints that appear in the answer feedback messages box after a student submits a particular answer that activates a pre-programmed hint via the <code>answerHints.pl</code> macro and a post-filter with answer hints for the answer checker.</li>
 
</ul>
 
</ul>
 
<br />
 
<br />
 
You may also be interested in [http://webwork.maa.org/wiki/ErrorMessageCustomization ErrorMessageCustomization]
 
You may also be interested in [http://webwork.maa.org/wiki/ErrorMessageCustomization ErrorMessageCustomization]
</p>
+
</div>
   
 
<p style="text-align:center;">
 
<p style="text-align:center;">
[[IndexOfProblemTechniques|Problem Techniques Index]]
+
[[Problem_Techniques|Problem Techniques Index]]
 
</p>
 
</p>
   
Line 31: Line 31:
 
DOCUMENT();
 
DOCUMENT();
 
loadMacros(
 
loadMacros(
"PGstandard.pl",
+
"PGstandard.pl",
"MathObjects.pl",
+
"MathObjects.pl",
"answerHints.pl",
+
"answerHints.pl",
 
);
 
);
   
Line 75: Line 75:
 
BEGIN_TEXT
 
BEGIN_TEXT
 
If \( f(t) = $f \), then \( f(3u) \) = \{ ans_rule(10) \}
 
If \( f(t) = $f \), then \( f(3u) \) = \{ ans_rule(10) \}
  +
$BR
  +
$BR
  +
\{
  +
knowlLink("Click for a hint",
  +
value=>'Substitute 3u wherever you see t in the formula for f.')
  +
\}
 
END_TEXT
 
END_TEXT
   
Line 91: Line 97:
 
<p>
 
<p>
 
<b>Main Text:</b>
 
<b>Main Text:</b>
We include a general answer hint in the block of text between the commands <code>BEGIN_HINT</code> (which is <code>HINT(EV3(<<'END_HINT'));</code> in older versions of WeBWorK) and <code>END_HINT</code>, which must be on their own lines and at the start of a line. The hint will automatically generate the word <b>HINT:</b> before the block of text that is the hint, so you don't need to add it manually. The modification of the context from <code>texStrings</code> and back to <code>normalStrings</code> ensures that MathObjects (formulas, etc.) will be beautifully typset.
 
  +
Knowls (little bits of knowledge) provide an always present link to a hint that, when clicked on, expands to reveal the hint or, when clicked on again, retracts to hide the hint. The <code>value</code> of a knowl should be plain text (math mode may cause problems, as it did for me using ww 2.9). It is possible to get math to display, but it requires using a few escape tricks: <code>value=>escapeSolutionHTML(EV3P('Substitute \\(3u\\) ...')), base64=>1)</code>. In particular, note the use of <code>escapeSolutionHTML(EV3P())</code> to do extra interpretation of the string formatting and also note the use of double backslashes <code>\\( \\)</code> for the math mode delimiters. No special macros are needed for Knowls.
  +
</p>
  +
<p>
  +
For hints that are revealed to students only after a certain number of submissions, we set <code>$showHint = 5;</code> and tell the students in the problem text that they will see a hint after 5 attempts.
  +
We include a general answer hint in the block of text between the commands <code>BEGIN_HINT</code> (which is <code>HINT(EV3(<<'END_HINT'));</code> in older versions of WeBWorK) and <code>END_HINT</code>, which must be on their own lines and at the start of a line. The hint will automatically generate the word <b>HINT:</b> before the block of text that is the hint, so you don't need to add it manually. The modification of the context from <code>texStrings</code> and back to <code>normalStrings</code> ensures that MathObjects (formulas, etc.) will be beautifully typset. No special macros are needed for hints inside of <code>BEGIN_HINT</code> and <code>END_HINT</code> text blocks.
 
</p>
 
</p>
 
</td>
 
</td>
Line 103: Line 113:
 
$showPartialCorrectAnswers = 1;
 
$showPartialCorrectAnswers = 1;
   
ANS($answer->cmp()
+
ANS($answer->cmp()->withPostFilter(AnswerHints(
->withPostFilter(AnswerHints(
 
 
Formula("6 t") => "Are you using the correct variable?",
 
Formula("6 t") => "Are you using the correct variable?",
 
Formula("6 u") => "Good work!",
 
Formula("6 u") => "Good work!",
))
+
)));
);
 
 
</pre>
 
</pre>
 
<td style="background-color:#eeccff;padding:7px;">
 
<td style="background-color:#eeccff;padding:7px;">
 
<p>
 
<p>
 
<b>Answer Evaluation:</b>
 
<b>Answer Evaluation:</b>
To generate specific, customized answer hints for particular answers, we use the <code>AnswerHints</code> postfilter provided by <code>answerHints.pl</code>. The answer hints should be provided by a particular answer, followed by the hash table association operator <code>=&gt;</code>, followed by a string that will show up in the messages portion of the answer preview and feedback box when students submit their answers. You may include as many answer and hint pairs as you like, and even use subroutines in them (see [http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/answerHints.pl answerHints.pl] for more on this).
+
To generate specific, customized answer hints for particular answers, we use the <code>AnswerHints</code> postfilter provided by <code>answerHints.pl</code>. The answer hints should be provided by a particular answer, followed by the hash table association operator <code>=&gt;</code>, followed by a string that will show up in the messages portion of the answer preview and feedback box when students submit their answers. You may include as many answer and hint pairs as you like, and even use subroutines in them (see [http://webwork.maa.org/pod/pg/macros/answerHints.html answerHints.pl] for more on this).
 
</p>
 
</p>
 
<p>
 
<p>
 
If the same error message should be given for several different answers, you should make a square bracketed list of those answers. For example, if the variables x, t, and u were all in the context, we could use
 
If the same error message should be given for several different answers, you should make a square bracketed list of those answers. For example, if the variables x, t, and u were all in the context, we could use
 
<pre>
 
<pre>
ANS($answer->cmp()
+
ANS($answer->cmp()->withPostFilter(AnswerHints(
->withPostFilter(AnswerHints(
 
 
[Compute("6 t"),Compute("6 x")] =>
 
[Compute("6 t"),Compute("6 x")] =>
 
"Are you using the correct variable?",
 
"Are you using the correct variable?",
))
+
)));
);
 
 
</pre>
 
</pre>
 
</p>
 
</p>
Line 125: Line 135:
 
If the MathObjects answer evaluator normally generates a message, the default is not to change a message that is already in place. To override a message generated by a MathObjects answer evaluator, you should set <code>replaceMessage=&gt;1</code> as below.
 
If the MathObjects answer evaluator normally generates a message, the default is not to change a message that is already in place. To override a message generated by a MathObjects answer evaluator, you should set <code>replaceMessage=&gt;1</code> as below.
 
<pre>
 
<pre>
ANS($answer->cmp()
+
ANS($answer->cmp()->withPostFilter(AnswerHints(
->withPostFilter(AnswerHints(
 
 
Compute("6 u") => ["Good work!",replaceMessage=>1],
 
Compute("6 u") => ["Good work!",replaceMessage=>1],
))
+
)));
);
 
 
</pre>
 
</pre>
 
</p>
 
</p>
Line 135: Line 145:
   
 
<p style="text-align:center;">
 
<p style="text-align:center;">
[[IndexOfProblemTechniques|Problem Techniques Index]]
+
[[Problem_Techniques|Problem Techniques Index]]
 
</p>
 
</p>
   
Line 143: Line 153:
   
 
<ul>
 
<ul>
<li>POD documentation: [http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/answerHints.pl answerHints.pl]</li>
+
<li>POD documentation: [http://webwork.maa.org/pod/pg/macros/answerHints.html answerHints.pl]</li>
<li>PG macro code: [http://cvs.webwork.rochester.edu/viewcvs.cgi/pg/macros/answerHints.pl answerHints.pl]</li>
+
<li>PG macro code: [http://webwork.maa.org/viewvc/system/trunk/pg/macros/answerHints.pl?view=log answerHints.pl]</li>
 
</ul>
 
</ul>
   
   
 
<ul>
 
<ul>
<li>POD documentation: [http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/problemPanic.pl.html problemPanic.pl.html]</li>
+
<li>POD documentation: [http://webwork.maa.org/pod/pg/macros/problemPanic.html problemPanic.pl]</li>
<li>PG macro code: [http://cvs.webwork.rochester.edu/viewcvs.cgi/pg/macros/problemPanic.pl problemPanic.pl]</li>
+
<li>PG macro code: [http://webwork.maa.org/viewvc/system/trunk/pg/macros/problemPanic.pl?view=log problemPanic.pl]</li>
 
</ul>
 
</ul>

Revision as of 17:43, 7 April 2021

Answer Hints


This PG code shows how to include three different kinds of answer hints:

  • General answer hints that help students get started on a problem and are always available via "Knowls".
  • General answer hints that help students get started on a problem and are made available after a student has submitted an answer at least once (a "Show hints" checkbox appears near the "Submit Answers" button) via a BEGIN_HINT / END_HINT block of text.
  • Specific, customized answer hints that appear in the answer feedback messages box after a student submits a particular answer that activates a pre-programmed hint via the answerHints.pl macro and a post-filter with answer hints for the answer checker.


You may also be interested in ErrorMessageCustomization

Problem Techniques Index

PG problem file Explanation
DOCUMENT(); 
loadMacros(
  "PGstandard.pl",
  "MathObjects.pl",
  "answerHints.pl",
);

TEXT(beginproblem());

Initialization: We need to include the macros file MathObjects.pl and answerHints.pl, which only works with MathObjects answer checkers (not old answer checkers). General answer hints only require the standard macros, but specific (customized) answer hints require the answerHints.pl macro.

Context("Numeric");
Context()->variables->are(t=>"Real",u=>"Real");

$f = Formula("2 t");
$answer = Formula("6 u");

Setup: We restrict the variables to t and u

Context()->texStrings;
BEGIN_TEXT
If \( f(t) = $f \), then \( f(3u) \) = \{ ans_rule(10) \} 
$BR
$BR
\{ 
knowlLink("Click for a hint", 
value=>'Substitute 3u wherever you see t in the formula for f.') 
\}
END_TEXT

$showHint = 5;
BEGIN_TEXT
$PAR
If you don't get this in $showHint tries, you can get a hint.
END_TEXT
BEGIN_HINT
Substitute \( 3u \) wherever you see \( t \) in the
formula for \( f(t) = $f \).
END_HINT
Context()->normalStrings;

Main Text: Knowls (little bits of knowledge) provide an always present link to a hint that, when clicked on, expands to reveal the hint or, when clicked on again, retracts to hide the hint. The value of a knowl should be plain text (math mode may cause problems, as it did for me using ww 2.9). It is possible to get math to display, but it requires using a few escape tricks: value=>escapeSolutionHTML(EV3P('Substitute \\(3u\\) ...')), base64=>1). In particular, note the use of escapeSolutionHTML(EV3P()) to do extra interpretation of the string formatting and also note the use of double backslashes \\( \\) for the math mode delimiters. No special macros are needed for Knowls.

For hints that are revealed to students only after a certain number of submissions, we set $showHint = 5; and tell the students in the problem text that they will see a hint after 5 attempts. We include a general answer hint in the block of text between the commands BEGIN_HINT (which is HINT(EV3(<<'END_HINT')); in older versions of WeBWorK) and END_HINT, which must be on their own lines and at the start of a line. The hint will automatically generate the word HINT: before the block of text that is the hint, so you don't need to add it manually. The modification of the context from texStrings and back to normalStrings ensures that MathObjects (formulas, etc.) will be beautifully typset. No special macros are needed for hints inside of BEGIN_HINT and END_HINT text blocks.

$showPartialCorrectAnswers = 1;

ANS($answer->cmp()->withPostFilter(AnswerHints( 
  Formula("6 t") => "Are you using the correct variable?",
  Formula("6 u") => "Good work!", 
)));

Answer Evaluation: To generate specific, customized answer hints for particular answers, we use the AnswerHints postfilter provided by answerHints.pl. The answer hints should be provided by a particular answer, followed by the hash table association operator =>, followed by a string that will show up in the messages portion of the answer preview and feedback box when students submit their answers. You may include as many answer and hint pairs as you like, and even use subroutines in them (see answerHints.pl for more on this).

If the same error message should be given for several different answers, you should make a square bracketed list of those answers. For example, if the variables x, t, and u were all in the context, we could use

ANS($answer->cmp()->withPostFilter(AnswerHints(
  [Compute("6 t"),Compute("6 x")] => 
  "Are you using the correct variable?",
)));

If the MathObjects answer evaluator normally generates a message, the default is not to change a message that is already in place. To override a message generated by a MathObjects answer evaluator, you should set replaceMessage=>1 as below.

ANS($answer->cmp()->withPostFilter(AnswerHints(
  Compute("6 u") => ["Good work!",replaceMessage=>1],
)));

Problem Techniques Index