StringOrOtherType1
Revision as of 02:29, 3 December 2010 by Pearson (talk | contribs) (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;…')
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: |