StringOrOtherType1: Difference between revisions
Jump to navigation
Jump to search
(Created page with '<h2>Answer is a String, or a Number, or a Function, etc.</h2> 300px|thumb|right|Click to enlarge <p style="background-color:#f9f9f9;border:black solid 1px;…') |
No edit summary |
||
Line 119: | Line 119: | ||
<p> | <p> | ||
<b>Answer Evaluation:</b> | <b>Answer Evaluation:</b> | ||
When <code>$answer = Formula("2*x")</code> and a student enters the string <code>NONE</code>, they will not get any error message because when the answer checker expects a formula and gets a string it is set up not to balk. However, when <code>$answer = String("none")</code> and a student enters the formula <code>2x</code>, they will get an error message. This is because the answer checker is expecting a string and gets a formula, and when this happens it | When <code>$answer = Formula("2*x")</code> and a student enters the string <code>NONE</code>, they will not get any error message because when the answer checker expects a formula and gets a string it is set up not to balk. However, when <code>$answer = String("none")</code> and a student enters the formula <code>2x</code>, they will get an error message. This is because the answer checker is expecting a string and gets a formula, and when this happens it balks. | ||
We must use <code>typeMatch=>Formula("x")</code> so that in the event the answer is a string, no error message will appear. | We must use <code>typeMatch=>Formula("x")</code> so that in the event the answer is a string, no error message will appear. | ||
</p> | </p> |
Revision as of 07:31, 3 December 2010
Answer is a String, or a Number, or a Function, etc.

This PG code shows how to prevent error messages from appearing when an answer may be one of several data types.
- Download file: File:StringOrOtherType1.txt (change the file extension from txt to pg when you save it)
- File location in NPL:
FortLewis/Authoring/Templates/Precalc/StringOrOtherType1.pg
PG problem file | Explanation |
---|---|
Problem tagging: |
|
DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl", "AnswerFormatHelp.pl", ); TEXT(beginproblem()); |
Initialization: |
Context("Numeric"); $y = random(0,4,1); if ($y < 4) { $answer = String("none"); } else { $answer = Formula("2*x"); } |
Setup: |
Context()->texStrings; BEGIN_TEXT Is there a line through the points \( (0,0) \), \( (1,2) \), and \( (2,$y) \)? If there is, the equation for this line. If not, enter ${BITALIC}NONE${EITALIC}. $BR $BR \( y = \) \{ ans_rule(20) \} \{ AnswerFormatHelp("formulas") \} END_TEXT Context()->normalStrings; |
Main Text: |
$showPartialCorrectAnswers = 1; ANS( $answer->cmp( typeMatch=>Formula("x") ) ); |
Answer Evaluation:
When |
Context()->texStrings; BEGIN_SOLUTION ${PAR}SOLUTION:${PAR} Solution explanation goes here. END_SOLUTION Context()->normalStrings; COMMENT('MathObject version.'); ENDDOCUMENT(); |
Solution: |