Difference between revisions of "AnswerOrderedList1"

From WeBWorK_wiki
Jump to navigation Jump to search
(Created page with '<h2>Answer is an Ordered List</h2> 300px|thumb|right|Click to enlarge <p style="background-color:#f9f9f9;border:black solid 1px;padding:3px;"> Th…')
 
(add historical tag and give links to newer problems.)
 
(4 intermediate revisions by 2 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/Sequences/AnswerOrderedList.html a newer version of this problem]</p>
  +
 
<h2>Answer is an Ordered List</h2>
 
<h2>Answer is an Ordered List</h2>
   
Line 5: Line 9:
 
This PG code shows how to write a question in which the answer is an ordered list, such as a sequence of numbers.
 
This PG code shows how to write a question in which the answer is an ordered list, such as a sequence of numbers.
 
</p>
 
</p>
* Download file: [[File:AnswerOrderedList1.txt]] (change the file extension from txt to pg when you save it)
 
  +
* PGML location in OPL: [https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/Sequences/AnswerOrderedList1_PGML.pg FortLewis/Authoring/Templates/Sequences/AnswerOrderedList1_PGML.pg]
* File location in NPL: <code>FortLewis/Authoring/Templates/Sequences/AnswerOrderedList.pg</code>
 
   
 
<br clear="all" />
 
<br clear="all" />
Line 16: Line 19:
   
 
<tr valign="top">
 
<tr valign="top">
<th> PG problem file </th>
+
<th style="width: 40%"> PG problem file </th>
 
<th> Explanation </th>
 
<th> Explanation </th>
 
</tr>
 
</tr>
Line 43: Line 46:
   
 
loadMacros(
 
loadMacros(
"PGstandard.pl",
+
'PGstandard.pl',
"MathObjects.pl",
+
'MathObjects.pl',
"AnswerFormatHelp.pl",
+
'PGML.pl',
  +
'PGcourse.pl'
 
);
 
);
   
Line 73: Line 76:
 
}
 
}
   
$answer = join(", ",@seq);
+
$answer_string = join(', ',@seq);
$answer = Compute("$answer");
+
$answer_cmp = Compute("$answer_string")->cmp(ordered=>1);
 
</pre>
 
</pre>
 
</td>
 
</td>
Line 81: Line 84:
 
<b>Setup:</b>
 
<b>Setup:</b>
 
We create an empty array <code>@seq</code> and then fill it with scalars using direct assignment and a foreach loop. Since the entries in the array <code>@seq</code> do not have commas between them, we create a Perl string <code>$answer</code> that joins the entries of the array <code>@seq</code> by a comma followed by a space <code>", "</code>. Then, we make this string a MathObject by putting <code>Compute()</code> around it.
 
We create an empty array <code>@seq</code> and then fill it with scalars using direct assignment and a foreach loop. Since the entries in the array <code>@seq</code> do not have commas between them, we create a Perl string <code>$answer</code> that joins the entries of the array <code>@seq</code> by a comma followed by a space <code>", "</code>. Then, we make this string a MathObject by putting <code>Compute()</code> around it.
  +
</p>
  +
<p>
  +
Since the answer is a MathObject List, which is by default unordered, we must specify that the answer checker use <code>ordered=&gt;1</code>
 
</p>
 
</p>
 
</td>
 
</td>
Line 90: Line 96:
 
<td style="background-color:#ffdddd;border:black 1px dashed;">
 
<td style="background-color:#ffdddd;border:black 1px dashed;">
 
<pre>
 
<pre>
Context()->texStrings;
 
  +
BEGIN_PGML
BEGIN_TEXT
 
  +
If [` s_1 = [$seq[0]] `], [` s_2 = [$seq[1]] `], and
If \( s_1 = $seq[0] \), \( s_2 = $seq[1] \), and
 
  +
[` s_n = s_{n-1} + s_{n-2} `], find the first seven
\( s_n = s_{n-1} + s_{n-2} \), find the first seven
 
  +
terms of this sequence, including [` s_1 `] and
terms of this sequence, including \( s_1 \) and
 
  +
[` s_2 `]. Enter your answer as a comma separated
\( s_2 \). Enter your answer as a comma separated
 
 
list of numbers.
 
list of numbers.
$BR
 
  +
$BR
 
  +
Sequence = [_____]{$answer_cmp}
Sequence = \{ ans_rule(40) \}
 
  +
\{ AnswerFormatHelp("numbers") \}
+
[@ helpLink('numbers') @]*
END_TEXT
+
END_PGML
Context()->normalStrings;
 
 
</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>
</p>
 
</td>
 
</tr>
 
 
<!-- Answer evaluation section -->
 
 
<tr valign="top">
 
<td style="background-color:#eeddff;border:black 1px dashed;">
 
<pre>
 
$showPartialCorrectAnswers=1;
 
 
ANS( $answer->cmp(ordered=>1) );
 
</pre>
 
<td style="background-color:#eeccff;padding:7px;">
 
<p>
 
<b>Answer Evaluation:</b>
 
Since the answer is a MathObject List, which is by default unordered, we must specify that the answer checker use <code>ordered=&gt;1</code>
 
 
</p>
 
</p>
 
</td>
 
</td>
Line 134: Line 122:
 
Context()->texStrings;
 
Context()->texStrings;
 
BEGIN_SOLUTION
 
BEGIN_SOLUTION
${PAR}SOLUTION:${PAR}
 
 
Solution explanation goes here.
 
Solution explanation goes here.
 
END_SOLUTION
 
END_SOLUTION
Line 157: Line 144:
   
 
[[Category:Top]]
 
[[Category:Top]]
[[Category:Authors]]
+
[[Category:Sample Problems]]
  +
[[Category:Subject Area Templates]]

Latest revision as of 06:43, 18 July 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

Answer is an Ordered List

Click to enlarge

This PG code shows how to write a question in which the answer is an ordered list, such as a sequence of numbers.


Templates by Subject Area

PG problem file Explanation

Problem tagging data

Problem tagging:

DOCUMENT();

loadMacros(
  'PGstandard.pl',
  'MathObjects.pl',
  'PGML.pl',
  'PGcourse.pl'
);

TEXT(beginproblem());

Initialization:

Context("Numeric");

@seq = ();
$seq[0] = 1;
$seq[1] = 1;
foreach my $i (2..6) {
  $seq[$i] = $seq[$i-1] + $seq[$i-2];
}

$answer_string = join(', ',@seq);
$answer_cmp = Compute("$answer_string")->cmp(ordered=>1);

Setup: We create an empty array @seq and then fill it with scalars using direct assignment and a foreach loop. Since the entries in the array @seq do not have commas between them, we create a Perl string $answer that joins the entries of the array @seq by a comma followed by a space ", ". Then, we make this string a MathObject by putting Compute() around it.

Since the answer is a MathObject List, which is by default unordered, we must specify that the answer checker use ordered=>1

BEGIN_PGML
If [` s_1 = [$seq[0]] `], [` s_2 = [$seq[1]] `], and
[` s_n = s_{n-1} + s_{n-2} `], find the first seven
terms of this sequence, including [` s_1 `] and
[` s_2 `].  Enter your answer as a comma separated
list of numbers.

Sequence = [_____]{$answer_cmp}

[@ helpLink('numbers') @]*
END_PGML

Main Text:

Context()->texStrings;
BEGIN_SOLUTION
Solution explanation goes here.
END_SOLUTION
Context()->normalStrings;

COMMENT('MathObject version.');

ENDDOCUMENT();

Solution:

Templates by Subject Area