46
7 AUTHORING NUMERICAL, FORMULA, CUSTOM RESPONSE QUESTIONS
37
1. The Script is the heart of advanced Numerical Response problems. It can be used to
decide some of the parameters of the problem, compute the answer to the problem,
and do just about anything else you can imagine. The Script language is Perl. You
do not need to know Perl to use the Script block because we will be stepping through
some advanced examples in this chapter, but knowing Perl can help.
2. Like other problem types, the Text Block is used to display the problem the student
will see. In addition, you can placevariables in the Text Block based on computations
done in the Script.
3. The Answer is the answer the system is looking for. The answer can use variables
calculated/defined in the problem’s Script block, allowing the answer to be determined
dynamically (including randomization).
4. A tolerance parameter determines how closely the system will require the student’s
answer to be in order to count it correct. The tolerance will default to zero if it is not
defined. The tolerance parameter should always be defined for a numerical problem
unless you are certain only integer answers are generated from your script and you
want students to reply with exactly that integer.
If the computer answer is a floating point number, the tolerance should not be zero.
Computers can only approximate computations involving real numbers. For instance,
acomputer’s [decimal] answer to the simple problem
1
3
is “0.33333333333333331”. It
should be an infinite series of 3’s, and there certainly shouldn’t be a “1” in the an-
swer, but no computer can represent an infinitely long, infinitely detailed real number.
Therefore, for any problem where the answer is not an integer, you need to allow a
tolerance factor, or the students will find it nearly impossible to exactly match the
computer’s idea of the answer. You may find the default tolerance too large for some
problems, so adjust as appropriate.
There are three kinds of tolerance. For some answer A and a tolerance T,
(a) an Absolute tolerance will take anything in the range A ± T. So if A = 10
and T = 2, then anything between 8 and 12 is acceptable. Any number in the
tolerance field without a % symbol is an absolute tolerance.
(b) a Relativetolerance will takeanything in therangeA±aT, whereT is interpreted
as a percentage/100. Any number in the tolerance field followed by a % symbol
is a relative tolerance. For example, a = 10 and t = 10% will accept anything
between 9 and 11.
(c) a tolerance that is a calculated variable (identified by $ sign as the first character).
For example, if an answer is $X,and for astudent possible values range from −$X1
to +$X1, you could choose T = $tolerance = $2X1/100; acceptable answers
would then be from $X − $tolerance to $X + $tolerance. (This is especially
useful when answers close to zero are possible for some students)
Some care is necessary when setting the display format of the computer answer. Before
testing the tolerance, LON-CAPA converts the computer answer, as generated in the
script block, according to the format attribute in the numericalresponse tag.
43
7 AUTHORING NUMERICAL, FORMULA, CUSTOM RESPONSE QUESTIONS
38
Next, the formatted comptuer answer is ”graded” relative to the significant figures pa-
rameter, if it is set (see section 5. If that test was passed, then a numerical comparison
of the Computer’s answer is made with the range of values:
($computerAnswer - $tolerance) < $formattedcomputerAnswer < ($computerAnswer
+$tolerance)
If the $formattedcomputerAnswer satisfies the permitted range, then ”correct” is re-
turned for the computer answer. It is good idea to test multiple randomizations to
make sure that your tolerance is compatible with the display format.
5. A significant figures specification is an optional setting that tells LON-CAPA how
many significant figures there are required for the answer, as either a single number,
e.g. 3, or a range of acceptable values, expressed as min,max. The significant figures
field can be omitted if you do not want to constrain the number of significant digits in
the student answers.
The system will check to ensure that the student’s answer contains the required sig-
nificant digits, useful in many scientific calculations. For example, if the computer
answer is “1.3”, and the problem requests three significant digits, specified by (en-
tered without quotes) “3”, the system will require the students to type “1.30”, even
though numerically, “1.3” and “1.30” are the same. A significant figure specification
of (entered without quotes) “3,4” means both “1.30” and “1.300” are acceptable.
Authors should be clear in the problem statements to tell students therequired number
or range of significant figures. If the student response does not contain the correct
number of significant digits, the LON-CAPA response will tell students to increase or
decrease the digits in their response, but it will not tell them how many digits to use.
These responses do not use up the number of trials, but such responses are frustrating
for students. If you would like to ensure that at least three significant digits are used,
then a specification such as 3,15 ensures at least three digits are used, but will quietly
accept up to 15.
Note that care must be used when using formatted computer answers together with
asignificant digit specification. You must ensure that the formatted answer provides
enough significant digits. To test the formatted answer, LON-CAPA converts the com-
puter answer, as generated in the script block, according to the format attribute in
the numericalresponse tag, e.g. 3f. Then LON-CAPA separately applies that num-
ber of significant figures to the computer answer, and if that result falls outside the
range specified in the significant digit parameter, it ”grades” the computer answer as
SIG
FAIL (i.e., not correct). It is a good idea to use the problem testing environment
to test plenty of different randomizations to make sure that your format and sig digits
parameters are compatible. This helps ensure that the formatted answer has enough
significant digits.
6. The Single Line Text Entry area, as in other problem types, allow you to manipulate
the text entry area the student will see.
40
7 AUTHORING NUMERICAL, FORMULA, CUSTOM RESPONSE QUESTIONS
39
7. Finally, the Hint should contain text which will help the students when they answer
incorrectly.
7.3 Simple Numerical Response Answer
Along with showing the Numerical Response editor, figure 17 also shows the parameters for
one of the simplest possible types ofnumerical responses. The Text Block has the problem’s
question, which is the static text “What is 2 + 2?” The Answer is “4”. The Hint has been
set to something appropriate for this problem. Everything else has the default values from
when the problem was created.
If you create a problem like this, hit Submit Changes, then hit View after the changes
have been submitted, you can try the problem out for yourself. Note the last box in the
HTML page has the answer LON-CAPA is looking for conveniently displayed for you, along
with the range the computer will accept and the number of significant digits the computer
requires when viewed by an Author.
As you’re playing with the problem, if you use up all your tries or get the answer correct
but wish to continue playing with the problem, use the Reset Submissions button to clear
your answer attempts.
7.4 Simple Script Usage
Totally static problems only scratch the surface of the Numerical Response capabilities. To
really explore the power of LON-CAPA, we need to start creating dynamic problems. But
before we can get to truly dynamic problems, we need to learn how to work with the Script
window.
A script consists of several statements, separated by semi-colons. A statement is
the smallest kind of instruction to the computer. Most problems will be built from several
statements.
Ascript can contain comments, which are not interpreted as statements by the com-
puter. Comments start with # and go to the end of that line. Thus, if a line starts with #,
the whole line is ignored. Comments can also begin in the middle of a line. It is a good idea
to comment more complicated scripts, as it can be very difficult to read a large script and
figure out what it does. It is a very good idea to adopt some sort of commenting standard,
especially if you are working in a group or you believe other people may use your problems
in the future.
• One of the simplest statements in LON-CAPA is a variable assignment. A variable
can hold any value in it. The variable name must start with a $. In the Script, you
need to assign to variables before you use them. Put this program into the Script field
of the Numerical Response:
$variable = 3;
This creates a variable named variable and assigns it the value of “3”. That’s one
statement.
46
7 AUTHORING NUMERICAL, FORMULA, CUSTOM RESPONSE QUESTIONS
40
Variable names are case sensitive, must start with a letter, and can only consist of letters,
numbers, and underscores. Variable names can be as long as you want.
There are many variable naming conventions, covering both how to name and how to
capitalize variables
1
.It is a good idea to adopt a standard. If you are working with a group,
you may wish to discuss it in your group and agree on a convention.
If you Submit Changes and View the problem, you will see nothing has changed. This
is because in order for a variable to be useful, it must be used. The variable can be used in
several places.
7.4.1 Variables in Scripts
Variables can be used later in the same script. For instance, we can add another line below
the $variable line as such:
$variable2 = $variable+2;
Now there is a variable called $variable2 with the the number “5” as its value.
Variables can also be used in strings, which are a sequence of letters. The underlying
language of the script, Perl, has a very large number of ways of using variables in strings,
but the easiest and most common way is to use normal double-quotes and just spell out the
name of the variable you want to use in the string, like this:
$stringVar = "I have a variable with the value $variable.";
This will put the string “I have a variable with the value 3.” into the variable named
“stringVar”.
If you are following this chapter as a tutorial, add the previous two lines to your Script
and submit the changes for the problem. There’s no need to view it; there’s still no visible
change.
7.4.2 Variables in the Text Block
Once you’ve defined variables in the Script, you can display them in the Text Block. For
example, using the previous three-line script we’ve created so far, you can place the following
in the Text Block:
See the 3: $variable<br />
See the string: <b>$stringVar</b><br />
If you save that and hit View, you should get what you see in figure 18. Note how the
“$variable” was turned into a 3, and the “$stringVar” was turned into “I have a variable
with the value 3.”
1
The author favors capsOnNewWords. Some people use underscore
to
separate
words. Many use up-
percaseletters to specify constants like PI or GOLDEN
MEAN.Some people always StartWithCapatalization.
What’s really important is to be consistent, so you don’t have to guess whether the variable you’re thinking
of is coefFriction, CoefFriction, COEF
FRICTION, or something else.
Documents you may be interested
Documents you may be interested