# TableOfValues1

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

## Fill in a Table of Values for a Function

Click to enlarge

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

PG problem file Explanation

Problem tagging:

```DOCUMENT();

"PGstandard.pl",
"MathObjects.pl",
);

TEXT(beginproblem());
```

Initialization:

```Context("Numeric");

\$f = Formula("3^(-x)");

foreach my \$i (0..2) {
}
```

Setup: We create an empty array `@answer` and use a foreach loop to simplify filling it with values.

```Context()->texStrings;
BEGIN_TEXT
If \( f(x) = \$f \), fill in the table of values with 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) {
}
```

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

COMMENT('MathObject version.');

ENDDOCUMENT();
```

Solution: