Difference between revisions of "TableOfValues1"

From WeBWorK_wiki
Jump to navigation Jump to search
(Created page with '<h2>Fill in a Table of Values for a Function</h2> <p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> This PG code shows how to create a table with answer b…')
 
Line 106: Line 106:
 
<p>
 
<p>
 
<b>Main Text:</b>
 
<b>Main Text:</b>
Notice that the table is inside a Perl code block <code>\{ \}</code> and that there are periods at the end of each line (after each of the subroutines <code>begintable(num. rows)</code> and <code>row( )</code>) except for the last line.
+
Notice that the table is inside a Perl code block <code>\{ \}</code> and that there are periods at the end of each line (after each of the subroutines <code>begintable(num cols)</code> and <code>row( )</code>) except for the last line. These periods are Perl's string concatenation operator.
 
</p>
 
</p>
 
</td>
 
</td>

Revision as of 19:37, 1 December 2010

Fill in a Table of Values for a Function

This PG code shows how to create a table with answer blanks in it.

  • Download file: File:TableOfValues1.txt (change the file extension from txt to pg when you save it)
  • File location in NPL: NationalProblemLibrary/FortLewis/Authoring/Templates/Precalc/TableOfValues1.pg

Templates by Subject Area

PG problem file Explanation

Problem tagging data

Problem tagging:

DOCUMENT();

loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"AnswerFormatHelp.pl",
);

TEXT(beginproblem());

Initialization:

Context("Numeric");

@answer = ();

$f = Formula("2^x");

foreach my $i (0..2) {
  $answer[$i] = $f->eval(x=>$i);
}

Setup:

Context()->texStrings;
BEGIN_TEXT
If \( f(x) = $f \), fill in the table of values with numbers.
\{ AnswerFormatHelp("numbers") \}
$PAR
$BCENTER
\{ 
begintable(5) .
row( "\(x = \)", "0", "1", "2" ) .
row( "\(f(x) = \)", ans_rule(5), ans_rule(5), ans_rule(5) ) .
endtable(); 
\}
$ECENTER
END_TEXT
Context()->normalStrings;

Main Text: Notice that the table is inside a Perl code block \{ \} and that there are periods at the end of each line (after each of the subroutines begintable(num cols) and row( )) except for the last line. These periods are Perl's string concatenation operator.

$showPartialCorrectAnswers = 1;

foreach my $i (0..2) {
  ANS( $answer[$i]->cmp() );
}

Answer Evaluation:

Context()->texStrings;
BEGIN_SOLUTION
${PAR}SOLUTION:${PAR}
Solution explanation goes here.
END_SOLUTION
Context()->normalStrings;

COMMENT('MathObject version.');

ENDDOCUMENT();

Solution:

Templates by Subject Area