Difference between revisions of "Scaffold"

From WeBWorK_wiki
Jump to navigation Jump to search
(added historical tag and gave updated problem link)
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
  +
{{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>
 
<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]] but with a much cleaner style for authors. The interface has tabs containing sections of the problem that can open and close. </em>
+
<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 71: Line 74:
 
# "always", or
 
# "always", or
 
# "never"
 
# "never"
is_open => "first_incorrect"
+
is_open => "first_incorrect",
 
# "correct_or_first_incorrect",
 
# "correct_or_first_incorrect",
 
# "incorrect",
 
# "incorrect",
Line 168: Line 171:
 
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>.
 
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>
  +
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.
  +
</p>
  +
<p>
  +
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>
  +
A section is considered to be "correct" when all the answers contained in it are correct.
  +
</p>
  +
<p>
  +
Warning: Putting the answer checkers outside the sections will change the conditions for when a section can be opened.
  +
</p>
  +
<p>
  +
More documentation is inside [https://github.com/openwebwork/pg/blob/master/macros/scaffold.pl the code on GitHub].
  +
</p>
  +
 
<p>
 
<p>
 
Note that MultiAnswer is used in this question to demonstrate that we can use it, unlike in some previous iterations of compound problems.
 
Note that MultiAnswer is used in this question to demonstrate that we can use it, unlike in some previous iterations of compound problems.

Latest revision as of 08:13, 28 June 2023

This article has been retained as a historical document. It is not up-to-date and the formatting may be lacking. Use the information herein with caution.

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.

Problem Techniques Index

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 scaffold.pl. In this example we include parserMultiAnswer.pl so that we can use that.

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(). Giving arguments to this changes when sections will open, and when they will be able to be opened. Options are listed below:

    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 Section::Begin("NAME OF SECTION");. This also takes the same arguments as Scaffold::Begin(), but only applies to the section. Similarly, we end the section with Section::End().

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 Scaffold::End().


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.)

Problem Techniques Index


  • PG macro: