WeBWorK Problems

Return string from Sage

Return string from Sage

by F. Heiderich -
Number of replies: 2
I would like to return a string from Sage to WeBWorK using the AskSage function, but have problems doing so.

The following trivial example works:

DOCUMENT(); 
loadMacros(
 "PGstandard.pl", # Standard macros for PG language
);
TEXT(beginproblem());
$SageCode=<<END;
print("\"hello\"")
END
$sageReply = AskSage($SageCode,{accepted_tos=>true,seed=>$problemSeed});
BEGIN_TEXT
Sage reply: $sageReply
END_TEXT
ENDDOCUMENT();

But the following fails:

DOCUMENT();

loadMacros(
 "PGstandard.pl", # Standard macros for PG language
);
TEXT(beginproblem());

$SageCode=<<END;
print("\"hello world\"")
END
$sageReply = AskSage($SageCode,{accepted_tos=>true,seed=>$problemSeed});
BEGIN_TEXT
Sage reply: $sageReply
END_TEXT
ENDDOCUMENT();

The space between "hello" and "world" seems to case the trouble. Can someone explain how to properly return strings from Sage to WeBWorK?


                        
In reply to F. Heiderich

Re: Return string from Sage

by John Travis -
Just to be certain, there is also the macro "sage.pl" which allows you to do an entire sage cell and allows for sending back a list of items if desired. Details at

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

Good luck with this.

In reply to John Travis

Re: Return string from Sage

by F. Heiderich -
No, I did not want to use a sage cell in the problem. I meant to use AskSage. If I remember correctly, I solved the problem using single quotation marks instead of double quotation marks in the argument for print in the sage code.