You can use the <eqn> and <EQN> tags to include one or more Perl statements in your questions. The value of the last Perl statement in the <eqn> or <EQN> tag is returned by the tag when the question is used.
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 | A circle of radius <eqn $r=randnum(3,7,1)> has area
<eqn $a=$pi * $r**2>. |
A circle of radius <EQN $r=randnum(3,7,1)> has area
<EQN $a=$pi * $r**2>. |
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 |
|
|
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>
Note If your Perl statements include the greater-than character (>), you must use the paired form.
Example Multiple-Choice Question Using <eqn> and <EQN>
The following table summarizes an actual question.
QID | |
---|---|
Name | |
Mode | Multiple-Choice |
Question |
|
Answer |
|
Display to Students |