Forum archive 2000-2006

Barbra Bannon - Why isn't 'e' resolving?

Barbra Bannon - Why isn't 'e' resolving?

by Arnold Pizer -
Number of replies: 0
inactiveTopicWhy isn't 'e' resolving? topic started 11/11/2001; 9:43:43 PM
last post 11/12/2001; 12:18:31 PM
userBarbra Bannon - Why isn't 'e' resolving?  blueArrow
11/11/2001; 9:43:43 PM (reads: 797, responses: 1)
Hello There,

I am trying to calculate 10*e**(3)... however, it is saying that e, an unquoted string will clash... and when I use $e it says it is undefined. In the manual it says that I can use e for 2.71 and pi for 3.14.

What is going on?

Thank you... -Barbra

<| Post or View Comments |>


userArnold K. Pizer - Re: Why isn't 'e' resolving?  blueArrow
11/12/2001; 12:18:31 PM (reads: 1032, responses: 0)
Hi Barbra,

This is a little tricky. It depends on whether the expression is evaluated within the body of the problem or within an answer evaluator.

If the expression is evaluated within the body of the problem then you must use valid Perl. Recent versions of WeBWorK allow you to use to use $E and $PI (capitals are important as you have discovered) for the numerical values. Thus for example you could say

$ans = 10*$E**3;
...
&ANS(std_str_cmp($ans));

Here $ans is evalated by Perl to be the number 200.855 and then then it is shipped off to the answer evaluator std_num_cmp.

Another option would be

$ans = "10e^3";
...
&ANS(std_str_cmp($ans));

Here $ans is a string which is shipped off to the answer evaluator std_num_cmp. The answer evaluator will evaluate the string so using e and ^ are legal. Note that in the first example WeBWorK will display the correct answer as a number 200.855 and in the second example the correct answer will be displayed as 10e^3. See http://webhost.math.rochester.edu/webworkdocs/discuss/msgReader$651 for more info on this.

Everything a student enters is evaluated by an answer evaluator, but when writing problems you need to keep track of what is being evalued by Perl. Usually this is everything unless you ship your answers off as strings. A mistake that is easy to make is to write $c = $a^3 instead of $a**3. This doesn't generate an error since ^ is a valid Perl bitwise operator but is not exponentiation so the results will not be what you expect.

<| Post or View Comments |>