We can figure out how to pass multiple values computed in Sage back to Webwork. Our example attempt is given below.
# DESCRIPTION
# Problem to test whether sage can print out multiple results
##############################
# Initialization
DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"AnswerFormatHelp.pl",
"PGcourse.pl",
"sage.pl",
);
TEXT(beginproblem());
###########################
# Setup
Context("Complex");
$p1 = -5;
$SageCode1=<<END;
p1 = $p1;
p2= -10;
K = p1+4;
Tp = 3/p1
Kv = K/abs(p1*p2)
kTpKv = [K, Tp, Kv];
## print kTpKv
print K
### How can we print K,Tp, Kv out and evaluate them separately in Webwork?
##That is ANS($K->cmp()); ANS($Tp->cmp()); ANS($Kv->cmp());
## Right now $result = AskSage can only get one value.
## One possible solution: If we print out a List = [K,Tp, Kv] from Sage, how ##can be get the three values out from List in WebWork?
END
$result = AskSage($SageCode1,{
accepted_tos=>true,
});
$K = Compute($result);
$Tp = Compute($result);
$Kv = Compute($result);
#############################
# Main text
Context()->texStrings;
BEGIN_TEXT
$BR
\( K = \) \{ ans_rule(10)\} , \(T_p = \) \{ ans_rule(10)\} and \(K_v = \) \{ ans_rule(10)\}
$PAR
END_TEXT
Context()->normalStrings;
##############################
# Answer evaluation
$showPartialCorrectAnswers = 1;
ANS($K->cmp());
ANS($Tp->cmp());
ANS($Kv->cmp());
ENDDOCUMENT();
WeBWorK Problems
passing multiple values from Sage to webwork
This forum has a limit to the number of forum postings you can make in a given time period - this is currently set at 10 posting(s) in 1 day