version 1.35, 2001/07/19 21:26:22
|
version 1.36, 2001/07/20 21:19:03
|
Line 60 sub start_numericalresponse {
|
Line 60 sub start_numericalresponse {
|
$result.=&Apache::edit::tag_start($target,$token,&Apache::lonxml::description($token)); |
$result.=&Apache::edit::tag_start($target,$token,&Apache::lonxml::description($token)); |
$result.=&Apache::edit::text_arg('Answer:','answer',$token); |
$result.=&Apache::edit::text_arg('Answer:','answer',$token); |
if ($token->[1] eq 'numericalresponse') { |
if ($token->[1] eq 'numericalresponse') { |
$result.=&Apache::edit::text_arg('Unit:','unit',$token) |
$result.=&Apache::edit::text_arg('Unit:','unit',$token,5); |
|
$result.=&Apache::edit::text_arg('Format:','format',$token,4); |
} else { |
} else { |
$result.=&Apache::edit::select_arg('Type:','type', |
$result.=&Apache::edit::select_arg('Type:','type', |
['cs','ci','mc'],$token) |
['cs','ci','mc'],$token) |
Line 70 sub start_numericalresponse {
|
Line 71 sub start_numericalresponse {
|
my $constructtag; |
my $constructtag; |
if ($token->[1] eq 'numericalresponse') { |
if ($token->[1] eq 'numericalresponse') { |
$constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval, |
$constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval, |
'answer','unit'); |
'answer','unit','format'); |
} else { |
} else { |
$constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval, |
$constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval, |
'answer','type'); |
'answer','type'); |
Line 121 sub end_numericalresponse {
|
Line 122 sub end_numericalresponse {
|
my $award = $Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"}; |
my $award = $Apache::lonhomework::history{"resource.$Apache::inputtags::part.solved"}; |
my $status = $Apache::inputtags::status['-1']; |
my $status = $Apache::inputtags::status['-1']; |
if ($award =~ /^correct/ || $status eq "SHOW_ANSWER" ) { |
if ($award =~ /^correct/ || $status eq "SHOW_ANSWER" ) { |
my $answervar=&Apache::run::run("{$$parstack['-1'];".'return $answer}',$safeeval); |
my $answervar=&Apache::lonxml::get_param('answer',$parstack,$safeeval); |
my (@answers)=&Apache::run::run("$answervar",$safeeval); |
my (@answers)=&Apache::run::run("return $answervar",$safeeval,1); |
my $unit=&Apache::run::run("{$$parstack['-1'];".'return $unit}',$safeeval); |
if (!defined($answers[0])) { $answers[0]=$answervar; } else { |
|
&Apache::lonxml::debug("answers is $#answers :$answers[0]:"); |
|
} |
|
my $formatvar=&Apache::lonxml::get_param('format',$parstack,$safeeval); |
|
my (@formats)=&Apache::run::run("return $formatvar",$safeeval,1); |
|
if (!defined($formats[0])) { $formats[0]=$formatvar; } |
|
|
|
my $unit=&Apache::lonxml::get_param('unit',$parstack,$safeeval); |
|
|
$result="<br></br>The computer got "; |
$result="<br></br>The computer got "; |
my $answer; |
|
foreach $answer (@answers) { $result.="$answer,"; } |
for (my $i=0; $i <= $#answers; $i++) { |
|
my $answer=$answers[$i]; |
|
my $format; |
|
if ($#formats > 0) { |
|
$format=$formats[$i]; |
|
} else { |
|
$format=$formats[0]; |
|
} |
|
if (defined($format)) { |
|
&Apache::lonxml::debug("formatting with :$format: answer :$answer:"); |
|
$result.=sprintf('%.'.$format,$answer).','; |
|
} else { |
|
&Apache::lonxml::debug("no format answer :$answer:"); |
|
$result.="$answer,"; |
|
} |
|
} |
chop $result; |
chop $result; |
$result.=" $unit.<br></br>"; |
$result.=" $unit.<br></br>"; |
} |
} |