WeBWorK Problems

Accept student answer as a string

Accept student answer as a string

by Henri Feiner -
Number of replies: 2

I want a student to respond with the string "one" as a place value for the number 2 and have the answer checked.

I keep running into various messages depending on different tries.

I am also interested in converting a numeric to a string.

Thanks in advance for responses.

syntax error at (eval 4431) line 16, near "(cmp"

Error details

 Problem2
ERROR caught by Translator while processing problem file:tmpEdit/setW10/blankProblem.pg.feinerh.tmp
****************
syntax error at (eval 4431) line 16, near "(cmp"

****************

------Input Read
1 DOCUMENT();
2 loadMacros(
3 "PGstandard.pl", # Standard macros for PG language
4 "MathObjects.pl",
5 );
6
7 TEXT(beginproblem());
8 Context()->normalStrings;
9 $two = "two";
10 #Context()->texStrings;
11 BEGIN_TEXT
12 Write 2 in words: \{$two2->ans_rule\}
13 END_TEXT
14 Context()->normalStrings;
15 $ANS=$two;
16 ANS(cmp->$two2);
17 ENDDOCUMENT();

-----

Request information

Time Fri Dec 11 02:03:15 2009
Method GET
URI /webwork2/wlac_math112/W10/2/
HTTP Headers
Keep-Alive 300
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
User-Agent Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.15) Gecko/2009101601 Firefox/3.0.15 (.NET CLR 3.5.30729)
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Connection keep-alive
Referer http://hosted2.webwork.rochester.edu/webwork2/wlac_math112/instructor/pgProblemEditor/W10/2/?effectiveUser=feinerh&key=tuBhgxZ39ASSZBjpwhPcRPuj5uai8uuP&user=feinerh
Accept-Encoding gzip,deflate
Accept-Language en-us,en;q=0.5
Host hosted2.webwork.rochester.edu
In reply to Henri Feiner

Re: Accept student answer as a string

by Michael Gage -
There are several difficulties. In reverse order:

The error message is from the statement in line 16 which should be

$two->cmp
since cmp is a method of the object $two, not vice versa.

However $two has not been initialized as an object.

$two = String("two");
would do that.

Finally string contexts require that any "legal" answer (whether correct or not) be specified. Students who enter an incorrect "legal" answer are told their answer is incorrect, students who enter an answer that isn't even "legal" are told that their response is not understood. This helps students distinguish typos from bad answers.

For further information -- first I strongly recommend obtaining the "learning Perl" book for reference about the underlying perl language. For information about using strings see information in the author's section of the wiki:

http://webwork.maa.org/wiki/StringsInContext

and if you need to add many "legal" strings at once consult
http://webwork.maa.org/doc/cvs/pg_CURRENT/macros/parserAutoStrings.pl.html

AutoStrings can even make every string "legal" which reduces coding but also sacrifices error checking of the students' answers.

Hope this helps.

--Mike