https://webwork.maa.org/mediawiki_new/api.php?action=feedcontributions&user=Zullil&feedformat=atomWeBWorK_wiki - User contributions [en]2024-03-28T13:13:27ZUser contributionsMediaWiki 1.34.0https://webwork.maa.org/mediawiki_new/index.php?title=Scaffold&diff=19735Scaffold2020-06-24T22:59:37Z<p>Zullil: Missing comma</p>
<hr />
<div><h2>Simple Scaffolded, MultiPart Problems Worked Sequentially</h2><br />
<br />
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"><br />
<em>This is the PG code to create a scaffolded problem with multiple parts that are displayed sequentially. This way uses a recent macro, <code>scaffold.pl</code> that creates a neat student interface - similar to that of [[CompoundProblem5]] but with a much cleaner style for authors. The interface has tabs containing sections of the problem that can dynamically open and close. </em><br />
</p><br />
<br />
<p style="text-align:center;"><br />
[[Problem_Techniques|Problem Techniques Index]]<br />
</p><br />
<br />
<table cellspacing="0" cellpadding="2" border="0"><br />
<tr valign="top"><br />
<th> PG problem file </th><br />
<th> Explanation </th><br />
</tr><br />
<br />
<tr valign="top"><br />
<td style="background-color:#ddffdd;border:black 1px dashed;"><br />
<pre><br />
DOCUMENT();<br />
loadMacros(<br />
"PGstandard.pl",<br />
"PGML.pl",<br />
"MathObjects.pl",<br />
"parserMultiAnswer.pl",<br />
"scaffold.pl",<br />
"PGcourse.pl",<br />
);<br />
TEXT(beginproblem());<br />
$showPartialCorrectAnswers = 1;<br />
</pre><br />
</td><br />
<td style="background-color:#ccffcc;padding:7px;"><br />
<p><br />
<b>Initialization:</b><br />
We need make no changes to the initialization section of the file besides including <code>scaffold.pl</code>. In this example we include <code>parserMultiAnswer.pl</code> so that we can use that.<br />
</p><br />
</td><br />
</tr><br />
<br />
<br />
<tr valign="top"><br />
<td style="background-color:#ffffdd;border:black 1px dashed;"><br />
<pre><br />
Context("Numeric");<br />
<br />
$a = Compute(random(2,9,1));<br />
$c = Compute(random(1,9,1));<br />
$b = Compute(random(2,6,1));<br />
if ($a*$c > 0) {$b += floor(sqrt(4*$a*$c))}<br />
<br />
$quadratic = Formula("$a x^2 + $b x + $c");<br />
$x1 = (-$b + sqrt($b**2-4*$a*$c))/(2*$a);<br />
$x2 = (-$b - sqrt($b**2-4*$a*$c))/(2*$a);<br />
<br />
###########################################<br />
# The scaffold<br />
Scaffold::Begin();<br />
</pre><br />
</td><br />
<td style="background-color:#ffffcc;padding:7px;"><br />
<p><br />
<b>Setup:</b><br />
In the problem set-up section of the file we define some variables that we will use in the problem, as usual. In addition, we begin the scaffold by <code>Scaffold::Begin()</code>. Giving arguments to this changes when sections will open, and when they will be able to be opened. Options are listed below:<br />
</p><br />
<pre><br />
Scaffold::Begin(<br />
can_open => "when_previous_correct", <br />
# "first_incorrect", <br />
# "incorrect",<br />
# "always", or <br />
# "never"<br />
is_open => "first_incorrect",<br />
# "correct_or_first_incorrect", <br />
# "incorrect",<br />
# "always", or <br />
# "never"<br />
instructor_can_open => "always", <br />
# "when_previous_correct",<br />
# "first_incorrect", <br />
# "incorrect", or <br />
# "never"<br />
after_AnswerDate_can_open => "always", <br />
# "when_previous_correct",<br />
# "first_incorrect", <br />
# "incorrect", or <br />
# "never"<br />
hardcopy_is_open => "always",<br />
# "first_incorrect" <br />
# "correct_or_first_incorrect", <br />
# "incorrect",<br />
# "always", or <br />
# "never"<br />
);<br />
</pre><br />
</td><br />
</tr><br />
<br />
<tr valign="top"><br />
<td style="background-color:#ffdddd;border:black 1px dashed;"><br />
<pre><br />
###########################################<br />
Section::Begin("Part 1: Identify the coefficients");<br />
<br />
BEGIN_PGML<br />
Consider the quadratic equation given by [`[$quadratic] = 0`].<br />
<br />
First, identify the coefficients for the quadratic using the standard form <br />
[`ax^2 + bx + c = 0`]:<br />
<br />
[`a`] = [____]{$a}, [`b`] = [____]{$b}, [`c`] = [____]{$c}<br />
END_PGML<br />
<br />
BEGIN_PGML_SOLUTION<br />
Take the coefficient of [`x^2`] for the value of [`a`], the coefficient<br />
of [`x`] for [`b`], and the constant for [`c`]. In this case, they<br />
are [`a = [$a]`], [`b = [$b]`], and [`c = [$c]`].<br />
END_PGML_SOLUTION<br />
<br />
Section::End();<br />
<br />
###########################################<br />
Section::Begin("Part 2: Solve using the quadratic formula");<br />
<br />
$multians1 = MultiAnswer($x1,$x2)->with(<br />
singleResult => 0,<br />
allowBlankAnswers => 1,<br />
checker => sub {<br />
my ($correct,$student,$self) = @_;<br />
my ($s1, $s2) = @{$student};<br />
my ($c1, $c2) = @{$correct};<br />
<br />
return (1,1) if ($c1 == $s1 and $c2 == $s2) or<br />
($c1 == $s2 and $c2 == $s1);<br />
return (1,0) if $c1 == $s1 or $c2 == $s1;<br />
return (0,1) if $c1 == $s2 or $c2 == $s2; <br />
return (0,0);<br />
}<br />
);<br />
<br />
BEGIN_PGML<br />
Using the quadratic formula, solve [`[$quadratic] = 0`]<br />
<br />
>> [`x`] = [______]{$multians1} or [`x`] = [______]{$multians1} <<<br />
END_PGML<br />
<br />
BEGIN_PGML_SOLUTION<br />
Recall that the quadratic equation is<br />
<br />
[``x = {-b \pm \sqrt{b^2 - 4ac} \over 2a}``].<br />
<br />
You already identified [`a = [$a]`], [`b = [$b]`], and [`c = [$c]`],<br />
so the results are:<br />
<br />
[``x = {-[$b] + \sqrt{[$b]^2 - 4[$a][$c]} \over 2[$a]} = [$x1]``]<br />
<br />
or<br />
<br />
[``x = {-[$b] - \sqrt{[$b]^2 - 4[$a][$c]} \over 2[$a]} = [$x2]``].<br />
END_PGML_SOLUTION<br />
<br />
Section::End();<br />
###########################################<br />
</pre><br />
<td style="background-color:#ffcccc;padding:7px;"><br />
<p><br />
<b>Main Text:</b><br />
The text section of the problem is now broken into the parts that we want the student to work sequentially. Begin sections with <code>Section::Begin("NAME OF SECTION");</code>. This also takes the same arguments as <code>Scaffold::Begin()</code>, but only applies to the section. Similarly, we end the section with <code>Section::End()</code>.<br />
</p><br />
<br />
<p><br />
Within a section, use BEGIN_TEXT/END_TEXT or BEGIN_PGML/END_PGML to create the text of the section as usual, and ANS() to assign answer checkers to the blanks that appear within the section.<br />
</p><br />
<p><br />
Whatever answer checkers are assigned within a section are the ones that are used to decide when that section can be opened by the student.<br />
</p><br />
</p><br />
A section is considered to be "correct" when all the answers contained in it are correct.<br />
</p><br />
<p><br />
Warning: Putting the answer checkers outside the sections will change the conditions for when a section can be opened.<br />
</p><br />
<p><br />
More documentation is inside [https://github.com/openwebwork/pg/blob/master/macros/scaffold.pl the code on GitHub].<br />
</p><br />
<br />
<p><br />
Note that MultiAnswer is used in this question to demonstrate that we can use it, unlike in some previous iterations of compound problems.<br />
</p><br />
</td><br />
</tr><br />
<br />
<tr valign="top"><br />
<td style="background-color:#eeddff;border:black 1px dashed;"><br />
<pre><br />
Scaffold::End();<br />
ENDDOCUMENT();<br />
</pre><br />
<td style="background-color:#eeccff;padding:7px;"><br />
<p><br />
<b>Answers and Solutions:</b><br />
We've included the answers and solutions in each section, so they don't appear here. However, once all of the sections are complete, we close the scaffold with <code>Scaffold::End()</code>.<br />
</p><br />
</td><br />
</tr><br />
</table><br />
<br />
<br />
<p><br />
As noted above, there are a number of other configurations for when sections open and are available to open in the problem. Some are listed here:<br />
<ul><br />
<li> <pre>Scaffold::Begin(<br />
can_open => "when_previous_correct",<br />
is_open => "first_incorrect"<br />
);</pre> - The defaults: only the active section is open, but students can open previous secitons if they want. </li><br />
<li> <pre>Scaffold::Begin(<br />
can_open => "when_previous_correct",<br />
is_open => "correct_or_first_incorrect"<br />
);</pre> - Sections stay open as the student works through the problem. </li><br />
<li> <pre>Scaffold::Begin(<br />
can_open => "first_incorrect",<br />
is_open => "first_incorrect"<br />
);</pre>: Students work through the problem seeing only one section at a time, and can't go back to previous secitons.</li><br />
<li> <pre>Scaffold::Begin(<br />
can_open => "always",<br />
is_open => "first_incorrect"<br />
);</pre> - Students can view and work on any section, but only the first incorrect one is shown initially. </li><br />
<li> <pre>Scaffold::Begin(<br />
can_open => "always",<br />
is_open => "incorrect"<br />
);</pre> - Students see all the parts initially, but the sections close as the student gets them correct. </li><br />
<li> <pre>Scaffold::Begin(<br />
can_open => "incorrect",<br />
is_open => "incorrect"<br />
);</pre> - Students see all the parts initially, but the sections close as the student gets them correct, and can't be reopened. </li><br />
<br />
</ul><br />
(These are all taken directly from the documentation in the macro file.)<br />
</p><br />
<br />
<p style="text-align:center;"><br />
[[Problem_Techniques|Problem Techniques Index]]<br />
</p><br />
<br />
[[Category:Problem Techniques]]<br />
<br />
<br />
<ul><br />
<li>PG macro: </li><br />
</ul></div>Zullil