## WeBWorK Problems

### Accepting all varialbes

by Carl Yao -
Number of replies: 0
Hello:

Is there a way to let WeBWorK accept any variable? For example, if the correct solution is {x|x>1}, and if a student typed in {Z|Z>1}, it would be considered correct?

Thank you!

Carl Yao
Math Instructor
Portland Community College

Sample code is here:

# WeBWorK problem written by Carl Yao
# Portland Community College
#
# Give a graph of an inequality, write the set notation and interval notation.
# Answer is like (3, inf).
#
# Last edited by Jordan 8/28/13; Carl Yao on 7/21/13
#
# ENDDESCRIPTION

## DBsubject('Algebra')
## DBchapter('Basic Algebra')
## DBsection('Inequalities')
## KEYWORDS('linear','inequality', 'number line','set notation','interval notation')
## DBCCSS('7.EE.4')
## TitleText1('')
## EditionText1('')
## AuthorText1('')
## Section1('')
## Problem1('')
## Author('Alex Jordan, Carl Yao, Chris Hughes')
## Institution('PCC')

##############################################

DOCUMENT();

"PGgraphmacros.pl",
"PGstandard.pl",
"MathObjects.pl",
"PGML.pl",
"parserPopUp.pl",
"contextInequalitySetBuilder.pl",
"PGcourse.pl",
);

##############################################
TEXT(beginproblem());
Context("Numeric");

$a = random(-4,4,0.5);$symbol = '>';

InequalitySetBuilder::UseVerticalSuchThat();
Context("InequalitySetBuilder-Only");
$setans = Compute("{ x | x$symbol $a}"); Context("Interval"); Context()->flags->set("formatStudentAnswer"=>'parsed');$intans = Compute("($a,inf)"); Context("Numeric"); %answer = (leftType => 'open', rightType => 'inf', #use 'inf' regardles of +/- inf );$aspectRatio = 1/8;
$horPixel = 400;$verPixel = $horPixel*$aspectRatio;
$screenXSize =$horPixel;
$screenYSize =$screenXSize*$aspectRatio;$reach = 5;
$verticalSpace =$reach*$aspectRatio;$hardCopyPercent = 1000; #meaning 100%

#initializing...
@gr=();

#indices will be 0..$#gr in some order, with the index of the correct graph in the 0th position. @indices=(); #make the graphs for$leftType ('open','closed', 'inf')
{
for $rightType ('open','closed', 'inf') { my$tempgr = init_graph(-$reach,-$verticalSpace,$reach,$verticalSpace,
axes=>[$reach+1,0], size=>[$horPixel,$verPixel] ); @ticks = (); for my$j ((-$reach)..($reach)) {push(@ticks,$j);};$tempgr->h_ticks(0,"black",@ticks);
$tempgr->lb( new Label(0,-$verticalSpace/5,0,'black','center','top'));

if (($leftType eq 'inf' or$rightType eq 'inf') and !(($leftType eq 'inf' and$rightType eq 'inf')))
{
$tempgr->lb( new Label($a,-$verticalSpace/5,$a,'blue','center','top'));
if ($leftType eq 'open' or$rightType eq 'open')
{
$tempgr->stamps( open_circle($a,0,'blue') )
}
else
{
$tempgr->stamps( closed_circle($a,0,'blue') )
};
$tempgr->moveTo($a,0);
if ($leftType eq 'inf') {$tempgr->arrowTo(-0.99*$reach,0,'blue',3)} else {$tempgr->arrowTo(0.99*$reach,0,'blue',3)}; push(@gr,$tempgr);
if ($answer{leftType} ne$leftType or $answer{rightType} ne$rightType)
{push(@indices, $#gr);} else {unshift(@indices,$#gr);}
}

}};

$alt = "Graph of an interval on a number line. There is a hollow circle at$a and everything right of that is shaded.";

##############################################
$refreshCachedImages = 1; Context()->texStrings; BEGIN_TEXT Here is a graph of an interval.$PAR

$BCENTER \{ image( insertGraph($gr[ $indices[0] ]), width=>$screenXSize, height=>$screenYSize, tex_size=>$hardCopyPercent,
extra_html_tags=>'title="$alt" alt= "$alt" align="top"' ) \}
$ECENTER$PAR
END_TEXT
Context()->normalStrings;

BEGIN_PGML

* *inf* for [\infty],
* *[$GTS]=* for [\geq], * and *[$LTS]=* for [\leq]

Write this inequality in set-builder notation: [_____________________]

Write this inequality in interval notation: [_____________________]

END_PGML

##############################################

ANS( $setans->cmp() ); ANS($intans->cmp() );

BEGIN_PGML_SOLUTION

Since the given graph shades all the values greater than [[$a]] (but not equal to [[$a]]) the graph represents the inequality [x [$symbol] [$a]].

The corresponding set notation is [[$setans]]. The corresponding interval notation is [[$intans]].

END_PGML_SOLUTION

ENDDOCUMENT();