Difference between revisions of "Scaffold"
(Created page with "<h2>Scaffolded, MultiPart Problems Worked Sequentially</h2> <p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> <em>This is the PG code to create a scaff...") |
(added historical tag and gave updated problem link) |
||
(11 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
− | <h2>Scaffolded, MultiPart Problems Worked Sequentially</h2> |
||
+ | {{historical}} |
||
+ | |||
+ | <p style="font-size: 120%;font-weight:bold">This problem has been replaced with [https://openwebwork.github.io/pg-docs/sample-problems/Misc/Scaffolding.html a newer version of this problem]</p> |
||
+ | <h2>Simple Scaffolded, MultiPart Problems Worked Sequentially</h2> |
||
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> |
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> |
||
− | <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 |
+ | <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> |
</p> |
</p> |
||
Line 9: | Line 12: | ||
</p> |
</p> |
||
− | <strong>Using answer hashes</strong> |
||
− | <p> |
||
− | This way of creating a compound problem has the advantage of being slightly cleaner from the perspective of students working the problem. |
||
− | </p> |
||
<table cellspacing="0" cellpadding="2" border="0"> |
<table cellspacing="0" cellpadding="2" border="0"> |
||
<tr valign="top"> |
<tr valign="top"> |
||
Line 24: | Line 23: | ||
DOCUMENT(); |
DOCUMENT(); |
||
loadMacros( |
loadMacros( |
||
− | "PGstandard.pl", |
+ | "PGstandard.pl", |
− | " |
+ | "PGML.pl", |
− | " |
+ | "MathObjects.pl", |
+ | "parserMultiAnswer.pl", |
||
+ | "scaffold.pl", |
||
+ | "PGcourse.pl", |
||
); |
); |
||
TEXT(beginproblem()); |
TEXT(beginproblem()); |
||
+ | $showPartialCorrectAnswers = 1; |
||
</pre> |
</pre> |
||
</td> |
</td> |
||
Line 34: | Line 34: | ||
<p> |
<p> |
||
<b>Initialization:</b> |
<b>Initialization:</b> |
||
− | We need make no changes to the initialization section of the file. In this example we include <code> |
+ | 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. |
</p> |
</p> |
||
</td> |
</td> |
||
Line 43: | Line 43: | ||
<td style="background-color:#ffffdd;border:black 1px dashed;"> |
<td style="background-color:#ffffdd;border:black 1px dashed;"> |
||
<pre> |
<pre> |
||
− | $a = random(1,9,2); |
||
+ | Context("Numeric"); |
||
− | $evenOdd = PopUp( [ "?", "even", "odd" ], |
||
− | "odd" ); |
||
− | $evenNum = Compute( 2 ); |
||
+ | $a = Compute(random(2,9,1)); |
||
+ | $c = Compute(random(1,9,1)); |
||
+ | $b = Compute(random(2,6,1)); |
||
+ | if ($a*$c > 0) {$b += floor(sqrt(4*$a*$c))} |
||
+ | |||
+ | $quadratic = Formula("$a x^2 + $b x + $c"); |
||
+ | $x1 = (-$b + sqrt($b**2-4*$a*$c))/(2*$a); |
||
+ | $x2 = (-$b - sqrt($b**2-4*$a*$c))/(2*$a); |
||
+ | |||
+ | ########################################### |
||
+ | # The scaffold |
||
+ | Scaffold::Begin(); |
||
</pre> |
</pre> |
||
</td> |
</td> |
||
Line 53: | Line 62: | ||
<p> |
<p> |
||
<b>Setup:</b> |
<b>Setup:</b> |
||
− | In the problem set-up section of the file we define some variables that we will use in the problem, as usual. |
+ | 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: |
</p> |
</p> |
||
+ | <pre> |
||
+ | Scaffold::Begin( |
||
+ | can_open => "when_previous_correct", |
||
+ | # "first_incorrect", |
||
+ | # "incorrect", |
||
+ | # "always", or |
||
+ | # "never" |
||
+ | is_open => "first_incorrect", |
||
+ | # "correct_or_first_incorrect", |
||
+ | # "incorrect", |
||
+ | # "always", or |
||
+ | # "never" |
||
+ | instructor_can_open => "always", |
||
+ | # "when_previous_correct", |
||
+ | # "first_incorrect", |
||
+ | # "incorrect", or |
||
+ | # "never" |
||
+ | after_AnswerDate_can_open => "always", |
||
+ | # "when_previous_correct", |
||
+ | # "first_incorrect", |
||
+ | # "incorrect", or |
||
+ | # "never" |
||
+ | hardcopy_is_open => "always", |
||
+ | # "first_incorrect" |
||
+ | # "correct_or_first_incorrect", |
||
+ | # "incorrect", |
||
+ | # "always", or |
||
+ | # "never" |
||
+ | ); |
||
+ | </pre> |
||
</td> |
</td> |
||
</tr> |
</tr> |
||
Line 61: | Line 100: | ||
<td style="background-color:#ffdddd;border:black 1px dashed;"> |
<td style="background-color:#ffdddd;border:black 1px dashed;"> |
||
<pre> |
<pre> |
||
− | Context()->texStrings; |
||
+ | ########################################### |
||
− | BEGIN_TEXT |
||
+ | Section::Begin("Part 1: Identify the coefficients"); |
||
− | ${BBOLD}Part 1 of 2:$EBOLD |
||
− | $PAR |
||
− | Is \( $a \) even or odd? |
||
− | \{ $evenOdd->menu() \} |
||
− | END_TEXT |
||
− | Context()->normalStrings; |
||
− | ANS( $evenOdd->cmp() ); |
||
+ | BEGIN_PGML |
||
+ | Consider the quadratic equation given by [`[$quadratic] = 0`]. |
||
− | $ans_hash1 = $evenOdd->cmp()->evaluate( |
||
+ | First, identify the coefficients for the quadratic using the standard form |
||
− | $inputs_ref->{ANS_NUM_TO_NAME(1)} ); |
||
+ | [`ax^2 + bx + c = 0`]: |
||
− | if ( $ans_hash1->{score} == 1 ) { |
||
+ | [`a`] = [____]{$a}, [`b`] = [____]{$b}, [`c`] = [____]{$c} |
||
− | Context()->texStrings; |
||
+ | END_PGML |
||
− | BEGIN_TEXT |
||
− | ${BBOLD}Part 2 of 2:$EBOLD |
||
− | $PAR |
||
− | Enter an example of an even number, |
||
− | \(n\): \(n = \) \{ $evenNum->ans_rule() \} |
||
− | END_TEXT |
||
− | Context()->normalStrings; |
||
− | ANS( $evenNum->cmp( checker=>sub { |
||
+ | BEGIN_PGML_SOLUTION |
||
− | my ( $cor, $stu, $ans ) = @_; |
||
+ | Take the coefficient of [`x^2`] for the value of [`a`], the coefficient |
||
− | return 0 == ($stu % 2); } ) ); |
||
+ | of [`x`] for [`b`], and the constant for [`c`]. In this case, they |
||
+ | are [`a = [$a]`], [`b = [$b]`], and [`c = [$c]`]. |
||
+ | END_PGML_SOLUTION |
||
− | } # ends if ( $ans_hash1->{score} ) |
||
+ | Section::End(); |
||
+ | |||
+ | ########################################### |
||
+ | Section::Begin("Part 2: Solve using the quadratic formula"); |
||
+ | |||
+ | $multians1 = MultiAnswer($x1,$x2)->with( |
||
+ | singleResult => 0, |
||
+ | allowBlankAnswers => 1, |
||
+ | checker => sub { |
||
+ | my ($correct,$student,$self) = @_; |
||
+ | my ($s1, $s2) = @{$student}; |
||
+ | my ($c1, $c2) = @{$correct}; |
||
+ | |||
+ | return (1,1) if ($c1 == $s1 and $c2 == $s2) or |
||
+ | ($c1 == $s2 and $c2 == $s1); |
||
+ | return (1,0) if $c1 == $s1 or $c2 == $s1; |
||
+ | return (0,1) if $c1 == $s2 or $c2 == $s2; |
||
+ | return (0,0); |
||
+ | } |
||
+ | ); |
||
+ | |||
+ | BEGIN_PGML |
||
+ | Using the quadratic formula, solve [`[$quadratic] = 0`] |
||
+ | |||
+ | >> [`x`] = [______]{$multians1} or [`x`] = [______]{$multians1} << |
||
+ | END_PGML |
||
+ | |||
+ | BEGIN_PGML_SOLUTION |
||
+ | Recall that the quadratic equation is |
||
+ | |||
+ | [``x = {-b \pm \sqrt{b^2 - 4ac} \over 2a}``]. |
||
+ | |||
+ | You already identified [`a = [$a]`], [`b = [$b]`], and [`c = [$c]`], |
||
+ | so the results are: |
||
+ | |||
+ | [``x = {-[$b] + \sqrt{[$b]^2 - 4[$a][$c]} \over 2[$a]} = [$x1]``] |
||
+ | |||
+ | or |
||
+ | |||
+ | [``x = {-[$b] - \sqrt{[$b]^2 - 4[$a][$c]} \over 2[$a]} = [$x2]``]. |
||
+ | END_PGML_SOLUTION |
||
+ | |||
+ | Section::End(); |
||
+ | ########################################### |
||
</pre> |
</pre> |
||
<td style="background-color:#ffcccc;padding:7px;"> |
<td style="background-color:#ffcccc;padding:7px;"> |
||
<p> |
<p> |
||
<b>Main Text:</b> |
<b>Main Text:</b> |
||
− | The text section of the problem is now broken into the parts that we want the student to work sequentially. |
+ | 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>. |
</p> |
</p> |
||
− | <p> |
||
− | Note that if we have multiple answer blanks in the first part of the problem the numbers used to dereference the answer numbers must increment: e.g., if we had two true/false pop-ups, <code>$evenNum1</code> and <code>$evenNum2</code>, we would test for completeness of the first part of the problem with |
||
− | </p> |
||
− | <pre> |
||
− | $ans_hash1 = $evenNum1->cmp()->evaluate( |
||
− | $inputs_ref->{ANS_NUM_TO_NAME(1)} ); |
||
− | $ans_hash2 = $evenNum2->cmp()->evaluate( |
||
− | $inputs_ref->{ANS_NUM_TO_NAME(2)} ); |
||
− | if ( $ans_hash1->{score} == 1 && |
||
− | $ans_hash2->{score} == 1 ) { |
||
− | # part 2 of the problem |
||
− | </pre> |
||
− | <p> |
||
− | (The line breaks putting the argument of the <code>evaluate()</code> method are included only to keep the line lengths short and improve formatting in the multi-column format of this page.) |
||
− | </p> |
||
− | </td> |
||
− | </tr> |
||
− | <tr valign="top"> |
||
− | <td style="background-color:#eeddff;border:black 1px dashed;"> |
||
− | <pre> |
||
− | |||
− | ENDDOCUMENT(); |
||
− | </pre> |
||
− | <td style="background-color:#eeccff;padding:7px;"> |
||
<p> |
<p> |
||
− | <b>Answer evaluation:</b> |
||
+ | 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. |
||
− | We've included the answer evaluators in the conditionals bracketing the display of the text, so they do not appear here. Solutions would, of course. |
||
</p> |
</p> |
||
− | </td> |
||
− | </tr> |
||
− | </table> |
||
− | |||
<p> |
<p> |
||
− | <strong>Using compoundProblem.pl</strong> |
||
+ | 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. |
||
</p> |
</p> |
||
− | <p> |
||
− | This way of creating a compound problem has the advantage of being slightly easer to manage. |
||
</p> |
</p> |
||
− | <table cellspacing="0" cellpadding="2" border="0"> |
||
+ | A section is considered to be "correct" when all the answers contained in it are correct. |
||
− | <tr valign="top"> |
||
− | <th> PG problem file </th> |
||
− | <th> Explanation </th> |
||
− | </tr> |
||
− | |||
− | <tr valign="top"> |
||
− | <td style="background-color:#ddffdd;border:black 1px dashed;"> |
||
− | <pre> |
||
− | DOCUMENT(); |
||
− | loadMacros( |
||
− | "PGstandard.pl", |
||
− | "MathObjects.pl", |
||
− | "parserPopUp.pl", |
||
− | "compoundProblem.pl", |
||
− | ); |
||
− | TEXT(beginproblem()); |
||
− | </pre> |
||
− | </td> |
||
− | <td style="background-color:#ccffcc;padding:7px;"> |
||
− | <p> |
||
− | <b>Initialization:</b> |
||
− | In the initialization section of the file, load <code>compoundProblem.pl</code>. In this example we also include <code>parserPopUp.pl</code> so that we can use that. |
||
</p> |
</p> |
||
− | </td> |
||
− | </tr> |
||
− | |||
− | |||
− | <tr valign="top"> |
||
− | <td style="background-color:#ffffdd;border:black 1px dashed;"> |
||
− | <pre> |
||
− | $a = random(1,9,2); |
||
− | $evenOdd = PopUp( [ "?", "even", "odd" ], |
||
− | "odd" ); |
||
− | $evenNum = Compute( 2 ); |
||
− | |||
− | $cp = new compoundProblem( parts=>2, |
||
− | weights=>[1,2], |
||
− | nextStyle=>'Forced' ); |
||
− | </pre> |
||
− | </td> |
||
− | <td style="background-color:#ffffcc;padding:7px;"> |
||
<p> |
<p> |
||
− | <b>Setup:</b> |
||
+ | Warning: Putting the answer checkers outside the sections will change the conditions for when a section can be opened. |
||
− | In the problem set-up section of the file we define some variables that we will use in the problem, and then define the compoundProblem object <code>$cp</code> with the <code>new compoundProblem()</code> call. The arguments of <code>compoundProblem</code> are documented [http://webwork.maa.org/viewvc/system/trunk/pg/macros/compoundProblem.pl?view=markup in the source file], and include <code>parts=><i>n</i></code> (the number of parts in the problem), <code>weights=>[<i>n1</i>,...,<i>nm</i>]</code> (the relative weight for each part of the problem). Other arguments are indicated below. |
||
</p> |
</p> |
||
<p> |
<p> |
||
− | The key method of the <code>$cp</code> that is used to control what is displayed in the problem is the <code>part</code> method, which reports which part of the problem the students is working on; we use this to control the text displayed, as shown in the following section of the file. |
||
+ | More documentation is inside [https://github.com/openwebwork/pg/blob/master/macros/scaffold.pl the code on GitHub]. |
||
</p> |
</p> |
||
− | </td> |
||
− | </tr> |
||
− | <tr valign="top"> |
||
− | <td style="background-color:#ffdddd;border:black 1px dashed;"> |
||
− | <pre> |
||
− | Context()->texStrings; |
||
− | BEGIN_TEXT |
||
− | Is \( $a \) even or odd? |
||
− | \{ $evenOdd->menu() \} |
||
− | END_TEXT |
||
− | Context()->normalStrings; |
||
− | |||
− | ANS( $evenOdd->cmp() ); |
||
− | |||
− | if ( $cp->part > 1 ) { |
||
− | Context()->texStrings; |
||
− | BEGIN_TEXT |
||
− | Enter an example of an even number, |
||
− | \(n\): \(n = \) \{ $evenNum->ans_rule() \} |
||
− | END_TEXT |
||
− | Context()->normalStrings; |
||
− | |||
− | ANS( $evenNum->cmp( checker=>sub { |
||
− | my ( $cor, $stu, $ans ) = @_; |
||
− | return 0 == ($stu % 2); } ) ); |
||
− | |||
− | } # ends if ( $cp->part > 1 ) |
||
− | </pre> |
||
− | <td style="background-color:#ffcccc;padding:7px;"> |
||
<p> |
<p> |
||
− | <b>Main Text:</b> |
||
+ | Note that MultiAnswer is used in this question to demonstrate that we can use it, unlike in some previous iterations of compound problems. |
||
− | The text section of the problem is now broken into the parts that we want the student to work sequentially. Here we always display the first part of the problem, and then display the second part only after the student has correctly worked the first part and clicked "submit" to continue to the second part. The answer checkers are similarly associated with the text sections that are being displayed. |
||
</p> |
</p> |
||
</td> |
</td> |
||
Line 224: | Line 194: | ||
<td style="background-color:#eeddff;border:black 1px dashed;"> |
<td style="background-color:#eeddff;border:black 1px dashed;"> |
||
<pre> |
<pre> |
||
− | |||
+ | Scaffold::End(); |
||
ENDDOCUMENT(); |
ENDDOCUMENT(); |
||
</pre> |
</pre> |
||
<td style="background-color:#eeccff;padding:7px;"> |
<td style="background-color:#eeccff;padding:7px;"> |
||
<p> |
<p> |
||
− | <b> |
+ | <b>Answers and Solutions:</b> |
− | We've included the |
+ | 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>. |
</p> |
</p> |
||
</td> |
</td> |
||
</tr> |
</tr> |
||
</table> |
</table> |
||
+ | |||
<p> |
<p> |
||
− | As noted above, there are a number of other |
+ | 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: |
<ul> |
<ul> |
||
− | <li> <code>parts => <i>n</i></code>: The number of parts in the problem. If not provided, defaults to 1, which rather defeats the point of using this in the first place. </li> |
||
+ | <li> <pre>Scaffold::Begin( |
||
− | <li> <code>weights => [<i>n1,...,nm</i>]</code>: The relative weights to give to each part in the problem. For example, weights => [2,1,1] would cause the first part to be worth 50% of the points (twice the amount for each of the other two), while the second and third part would be worth 25% each. If weights are not supplied, the parts are weighted by the number of answer blanks in each part (and you must provide the total number of blanks in all the parts by supplying the totalAnswers option). </li> |
||
+ | can_open => "when_previous_correct", |
||
− | <li> <code>totalAnswers => <i>n</i></code>: The total number of answer blanks in all the parts put together (this is used when computing the per-part scores, if part weights are not provided). </li> |
||
+ | is_open => "first_incorrect" |
||
− | <li> <code>saveAllAnswers => <i>0 or 1</i></code>: Usually, the contents of named answer blanks from previous parts are made available to later parts using variables with the same name as the answer blank. Setting saveAllAnswers to 1 will cause ALL answer blanks to be available (via variables like $AnSwEr1, and so on). If not provided, defaults to 0. </li> |
||
+ | );</pre> - The defaults: only the active section is open, but students can open previous secitons if they want. </li> |
||
− | <li> <code>parserValues => <i>0 or 1</i></code>: Determines whether the answers from previous parts are returned as MathObjects (like those returned from Real(), Vector(), etc) or as strings (the unparsed contents of the student answer). If you intend to use the previous answers as numbers, for example, you would want to set this to 1 so that you would get the final result of any formula the student typed, rather than the formula itself as a character string. If not provided, defaults to 0. </li> |
||
+ | <li> <pre>Scaffold::Begin( |
||
− | <li> <code>nextVisible => <i>type</i></code>: Tells when the "go on to the next part" option is available to the student. The possible types include: <code>ifCorrect</code> (the default; next is available only when all the answers are correct), <code>Always</code> (next is always available (but note that students can't go back once they go on), and <code>Never</code> (the problem controls going on by itself). </li> |
||
+ | can_open => "when_previous_correct", |
||
− | <li> <code>nextStyle => <i>type</i></code>: Determines the style of "next" indicator to display (when it is available). The possible types include: <code>CheckBox</code> (the default), <code>Button</code>, <code>Forced</code> (forces students to go on when they next submit answers), and <code>HTML</code> (provide an arbitrary HTML string). </li> |
||
+ | is_open => "correct_or_first_incorrect" |
||
+ | );</pre> - Sections stay open as the student works through the problem. </li> |
||
+ | <li> <pre>Scaffold::Begin( |
||
+ | can_open => "first_incorrect", |
||
+ | is_open => "first_incorrect" |
||
+ | );</pre>: Students work through the problem seeing only one section at a time, and can't go back to previous secitons.</li> |
||
+ | <li> <pre>Scaffold::Begin( |
||
+ | can_open => "always", |
||
+ | is_open => "first_incorrect" |
||
+ | );</pre> - Students can view and work on any section, but only the first incorrect one is shown initially. </li> |
||
+ | <li> <pre>Scaffold::Begin( |
||
+ | can_open => "always", |
||
+ | is_open => "incorrect" |
||
+ | );</pre> - Students see all the parts initially, but the sections close as the student gets them correct. </li> |
||
+ | <li> <pre>Scaffold::Begin( |
||
+ | can_open => "incorrect", |
||
+ | is_open => "incorrect" |
||
+ | );</pre> - Students see all the parts initially, but the sections close as the student gets them correct, and can't be reopened. </li> |
||
+ | |||
</ul> |
</ul> |
||
(These are all taken directly from the documentation in the macro file.) |
(These are all taken directly from the documentation in the macro file.) |
||
Line 258: | Line 247: | ||
<ul> |
<ul> |
||
− | <li>PG macro: [http://webwork.maa.org/viewvc/system/trunk/pg/macros/compoundProblem.pl?view=markup compoundProblem.pl]</li> |
||
+ | <li>PG macro: </li> |
||
</ul> |
</ul> |
Latest revision as of 08:13, 28 June 2023
This problem has been replaced with a newer version of this problem
Simple Scaffolded, MultiPart Problems Worked Sequentially
This is the PG code to create a scaffolded problem with multiple parts that are displayed sequentially. This way uses a recent macro, scaffold.pl
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.
PG problem file | Explanation |
---|---|
DOCUMENT(); loadMacros( "PGstandard.pl", "PGML.pl", "MathObjects.pl", "parserMultiAnswer.pl", "scaffold.pl", "PGcourse.pl", ); TEXT(beginproblem()); $showPartialCorrectAnswers = 1; |
Initialization:
We need make no changes to the initialization section of the file besides including |
Context("Numeric"); $a = Compute(random(2,9,1)); $c = Compute(random(1,9,1)); $b = Compute(random(2,6,1)); if ($a*$c > 0) {$b += floor(sqrt(4*$a*$c))} $quadratic = Formula("$a x^2 + $b x + $c"); $x1 = (-$b + sqrt($b**2-4*$a*$c))/(2*$a); $x2 = (-$b - sqrt($b**2-4*$a*$c))/(2*$a); ########################################### # The scaffold Scaffold::Begin(); |
Setup:
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 Scaffold::Begin( can_open => "when_previous_correct", # "first_incorrect", # "incorrect", # "always", or # "never" is_open => "first_incorrect", # "correct_or_first_incorrect", # "incorrect", # "always", or # "never" instructor_can_open => "always", # "when_previous_correct", # "first_incorrect", # "incorrect", or # "never" after_AnswerDate_can_open => "always", # "when_previous_correct", # "first_incorrect", # "incorrect", or # "never" hardcopy_is_open => "always", # "first_incorrect" # "correct_or_first_incorrect", # "incorrect", # "always", or # "never" ); |
########################################### Section::Begin("Part 1: Identify the coefficients"); BEGIN_PGML Consider the quadratic equation given by [`[$quadratic] = 0`]. First, identify the coefficients for the quadratic using the standard form [`ax^2 + bx + c = 0`]: [`a`] = [____]{$a}, [`b`] = [____]{$b}, [`c`] = [____]{$c} END_PGML BEGIN_PGML_SOLUTION Take the coefficient of [`x^2`] for the value of [`a`], the coefficient of [`x`] for [`b`], and the constant for [`c`]. In this case, they are [`a = [$a]`], [`b = [$b]`], and [`c = [$c]`]. END_PGML_SOLUTION Section::End(); ########################################### Section::Begin("Part 2: Solve using the quadratic formula"); $multians1 = MultiAnswer($x1,$x2)->with( singleResult => 0, allowBlankAnswers => 1, checker => sub { my ($correct,$student,$self) = @_; my ($s1, $s2) = @{$student}; my ($c1, $c2) = @{$correct}; return (1,1) if ($c1 == $s1 and $c2 == $s2) or ($c1 == $s2 and $c2 == $s1); return (1,0) if $c1 == $s1 or $c2 == $s1; return (0,1) if $c1 == $s2 or $c2 == $s2; return (0,0); } ); BEGIN_PGML Using the quadratic formula, solve [`[$quadratic] = 0`] >> [`x`] = [______]{$multians1} or [`x`] = [______]{$multians1} << END_PGML BEGIN_PGML_SOLUTION Recall that the quadratic equation is [``x = {-b \pm \sqrt{b^2 - 4ac} \over 2a}``]. You already identified [`a = [$a]`], [`b = [$b]`], and [`c = [$c]`], so the results are: [``x = {-[$b] + \sqrt{[$b]^2 - 4[$a][$c]} \over 2[$a]} = [$x1]``] or [``x = {-[$b] - \sqrt{[$b]^2 - 4[$a][$c]} \over 2[$a]} = [$x2]``]. END_PGML_SOLUTION Section::End(); ########################################### |
Main Text:
The text section of the problem is now broken into the parts that we want the student to work sequentially. Begin sections with 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. 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. A section is considered to be "correct" when all the answers contained in it are correct. Warning: Putting the answer checkers outside the sections will change the conditions for when a section can be opened. More documentation is inside the code on GitHub. Note that MultiAnswer is used in this question to demonstrate that we can use it, unlike in some previous iterations of compound problems. |
Scaffold::End(); ENDDOCUMENT(); |
Answers and Solutions:
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 |
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:
-
Scaffold::Begin( can_open => "when_previous_correct", is_open => "first_incorrect" );
- The defaults: only the active section is open, but students can open previous secitons if they want. -
Scaffold::Begin( can_open => "when_previous_correct", is_open => "correct_or_first_incorrect" );
- Sections stay open as the student works through the problem. -
Scaffold::Begin( can_open => "first_incorrect", is_open => "first_incorrect" );
: Students work through the problem seeing only one section at a time, and can't go back to previous secitons. -
Scaffold::Begin( can_open => "always", is_open => "first_incorrect" );
- Students can view and work on any section, but only the first incorrect one is shown initially. -
Scaffold::Begin( can_open => "always", is_open => "incorrect" );
- Students see all the parts initially, but the sections close as the student gets them correct. -
Scaffold::Begin( can_open => "incorrect", is_open => "incorrect" );
- Students see all the parts initially, but the sections close as the student gets them correct, and can't be reopened.
(These are all taken directly from the documentation in the macro file.)
- PG macro: