Understanding the <eqn> and <EQN> Tags
The <eqn> and <EQN> tags are WebAssign tags that let you put Perl statements in your questions. Most often, these statements are used to set or read the values of variables in order to make the question behave in a certain way.
For example, to change the size of the answer box for numerical or fill-in-the-blank questions, you would add this code to Answer:
<EQN $size=5; ''>
This code consists of three parts:
- The <EQN> tag itself, which tells WebAssign that the enclosed values should be processed as Perl statements.
- The first Perl statement,
$size=5;which assigns the value 5 to the WebAssign variable $size, which is used to specify how wide the answer box should be. - The second Perl statement,
''which is an empty string. Because the result of the last Perl statement is always included in your question, answer key, or solution (depending on where the code occurs), the empty string is often used as the last statement.
Both the <eqn> and <EQN> tags include Perl statements, but they display values differently depending on whether they are used in Question, Answer, or Solution.
<eqn> | <EQN> | |
|---|---|---|
Intended Use | Use in Question and Solution. | Use in Answer. |
Example code |
|
|
Display in Question and Solution | A circle of radius 5 has area 78.5398163397448. | A circle of radius 5 has area 78.5398163397448. |
Behavior in Question and Solution | Displays numeric values up to 15 significant digits. | Displays numeric values up to 15 significant digits. |
Display in Answer | A circle of radius 5 has area 78.5. | A circle of radius 5 has area 78.5398163397448. |
Behavior in Answer |
|
|
Paired and Unpaired Forms
Both the <eqn> and <EQN> tags can be used in paired and unpaired forms.
The unpaired form consists of a single tag and is used most frequently to display values or in Answer. It has the following syntax (using either eqn or EQN):
<EQN perl_statement; perl_statement>The paired form consists of an opening tag and a closing tag and is usually used to include longer blocks of Perl statements. It has the following syntax (using either eqn or EQN):
<eqn> perl_statement; perl_statement </eqn>
If needed, open your question in the Question Editor.
Some questions are not searchable because of their Permission settings.
If
Do this
You know the question ID or name
- In the search box at the top of the page, select Question.
- Type the question name or ID and press Enter.
You own the question
- Click Questions › My Questions.
- Click the question name.
You organize your questions in folders
- Click Assignments › Folders and navigate to the folder with the question.
- Click the question name.
You want to use advanced search
- Click Questions › Search Questions.
Enter the search criteria you want to use.
To view only your questions, click me next to Author.
- Click Search.
If you own the question, click Edit next to your question.
If you do not own the question, click View, then click Open in Editor under Previewer Tools.
Start the <eqn> or <EQN> tag.
You can use either the paired or unpaired form, as described above.
Type the Perl statements that you want to perform.
End each Perl statement except for the last one with a semicolon (;). The value returned by the last statement is displayed as part of your question or answer key.
End the </eqn> or </EQN> tag.
- When using paired tags, the ending tag must match the start tag. You cannot, for example, start with <eqn> and end with </EQN>.
- When using the unpaired form, do not add a slash at the end of the tag as with XML tags. Just use the closing angle bracket (>).
Example Multiple-Choice Question Using <eqn> and <EQN> The following table summarizes an actual question. QID Name Mode Multiple-Choice Question <eqn> $weight = randnum(40,150,1); # pick a random integer between 40 and 150 $venuswt = decform($weight * 0.907, 0); # calculate weight on Venus $marswt = decform($weight * 0.377, 0); # calculate weight on Mars $jupiterwt = decform($weight * 2.364, 0); # calculate weight on Jupiter '' </eqn> If you weighed <eqn $weight> kg on Earth:<br> <ul> <li>Your weight on Venus would be <eqn $venuswt> kg</li> <li>Your weight on Mars would be <eqn $marswt> kg</li> <li>Your weight on Jupiter would be <eqn $jupiterwt> kg</li> </ul> On which planet would your mass be the least? <_> Answer <EQN $ORDERED=5; 'Earth'> Venus Mars Jupiter Your mass would be the same Display to Students 