 6.24 Tutorial: List-based Variables - Maple T.A. 2016 Help Instructor
Select your version: Maple T.A. 2017 | Maple T.A. 2016 | Maple T.A. 10

## 6.24 Tutorial: List-based Variables

You can use the algorithmic syntax to manage multiple scenarios or sets of randomized data in questions. Using list-based variables, you can use the same question statement but substitute corresponding sets of data throughout the question, answer, comment, hints, and solution statements.

### Example

Consider the case in which you want to create a chemistry problem that uses one of several sets or scenarios of data related to distinct elements. Each set contains a visual depiction (GIF file) and related data linked to various properties of the distinct elements.

To create a single problem that randomly chooses an element and substitutes its individualized properties into the question statement and other fields, use algorithm and answer statements as in the following examples.

#### (a) Single Index Case with Sixteen Scenarios

1. Use a single variable \$k as an index.
```\$k=rint(15);
```
1. Create individual variables for the first related property of each of the sixteen scenarios. In this case, the first related property is an image file depicting the molecular structure. Create a new variable \$molecule1 that uses the index to select the appropriate indexed data value (in this case, the correct image).
```\$molecule1x00="<img src=../classes/myclass/chap15/image01.gif>";
\$molecule1x01="<img src=../classes/myclass/chap15/image02.gif>";
\$molecule1x02="<img src=../classes/myclass/chap15/image03.gif>";
...
\$molecule1x15="<img src=../classes/myclass/chap15/image16.gif>";
\$molecule1=switch(\$k, \$molecule1x00, \$molecule1x01,  \$molecule1x02, ... ,\$molecule1x15);
```
1. Define the second related property for each scenario. Create a new variable that uses the index to select the appropriate indexed data value.
```\$property1x00="value...";
\$property1x01="value...";
...
\$property1x15="value...";
\$property1=switch(\$k, \$property1x00, \$property1x01,  ... , \$property1x15);
```
1. Define additional related properties for each scenario, and then select (using the index) and assign the appropriate values to new variables.

1. The final set of variables is the answer field (assuming that each different case has a different answer). Select the appropriate answer using the index.
```
\$ans00=50;
\$ans01=16;
..
\$ans15=3.6;
\$ans=switch(\$k, \$ans2x00, .. , \$ans2x15);
```

#### (b) Multiple Index Case

It may be the case that your question requires multiple indexes to your data. Consider the above case with only four elements (molecule1 to molecule4), where for each element there are four individualized sets of properties.

Assume that you have four images of molecules. To avoid redundancy (because molecule1 has only four values, but there are sixteen scenarios), use two indices. The first index, \$i, determines the element and image. The second index, \$k, determines the scenario. Depending on the value of \$i, the value of \$k is in one of the four ranges: 0-3, 4-7, 8-11, or 12-15. By using \$k, \$property1 (and other properties, and \$ans) match with the appropriate molecule1. To implement this, use the following statements.

```\$i=rint(4);
\$j=rint(4);
\$k=4*i+j;

\$molecule1x0="...";
\$molecule1x1="...";
\$molecule1x2="...";
\$molecule1x3="...";
\$molecule1=switch(\$i, \$molecule1x0, \$molecule1x1,..);

\$property1x00="..";
\$property1x01="..";
..
\$property1x15="..";
\$property1=switch(\$k, \$property1x00, .. , \$property1x15);

\$ans00=50;
\$ans01=16;
..
\$ans15=3.6;
\$ans=switch(\$k, \$ans2x00, .. , \$ans2x15);```