StringOrOtherType1: Difference between revisions
Paultpearson (talk | contribs) mNo edit summary |
(add historical tag and give links to newer problems.) |
||
(2 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
{{historical}} | |||
<p style="font-size: 120%;font-weight:bold">This problem has been replaced with [https://openwebwork.github.io/pg-docs/sample-problems/Algebra/StringOrOtherType.html a newer version of this problem]</p> | |||
<h2>Answer is a String, or a Number, or a Function, etc.</h2> | <h2>Answer is a String, or a Number, or a Function, etc.</h2> | ||
Line 5: | Line 10: | ||
This PG code shows how to prevent error messages from appearing when an answer may be one of several data types. | This PG code shows how to prevent error messages from appearing when an answer may be one of several data types. | ||
</p> | </p> | ||
* | * File location in OPL: [https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/Precalc/StringOrOtherType1.pg FortLewis/Authoring/Templates/Precalc/StringOrOtherType1.pg] | ||
* | * PGML location in OPL: [https://github.com/openwebwork/webwork-open-problem-library/blob/master/OpenProblemLibrary/FortLewis/Authoring/Templates/Precalc/StringOrOtherType1_PGML.pg FortLewis/Authoring/Templates/Precalc/StringOrOtherType1_PGML.pg] | ||
<br clear="all" /> | <br clear="all" /> |
Latest revision as of 10:06, 18 July 2023
This problem has been replaced with a newer version of this problem
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.
- File location in OPL: FortLewis/Authoring/Templates/Precalc/StringOrOtherType1.pg
- PGML location in OPL: FortLewis/Authoring/Templates/Precalc/StringOrOtherType1_PGML.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:
There are several predefined strings, such as |
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: |