version 1.256, 2015/10/30 03:49:55
|
version 1.262, 2020/12/05 05:01:18
|
Line 664 sub end_numericalresponse {
|
Line 664 sub end_numericalresponse {
|
my (@formats)=&Apache::lonxml::get_param_var('format',$parstack,$safeeval); |
my (@formats)=&Apache::lonxml::get_param_var('format',$parstack,$safeeval); |
|
|
my $unit=&Apache::lonxml::get_param_var('unit',$parstack,$safeeval); |
my $unit=&Apache::lonxml::get_param_var('unit',$parstack,$safeeval); |
|
my ($needsdollar,$needscomma); |
|
if ($unit =~ /\$/) { |
|
$needsdollar = 1; |
|
} |
|
if ($unit =~ /\,/) { |
|
$needscomma = 1; |
|
} |
|
|
if ($target eq 'answer') { |
if ($target eq 'answer') { |
$result.=&Apache::response::answer_header($tag,undef, |
$result.=&Apache::response::answer_header($tag,undef, |
scalar(keys(%answer))); |
scalar(keys(%answer))); |
Line 753 sub end_numericalresponse {
|
Line 760 sub end_numericalresponse {
|
my $ans=$answers[$i]; |
my $ans=$answers[$i]; |
my $fmt=$formats[0]; |
my $fmt=$formats[0]; |
if (@formats && $#formats) {$fmt=$formats[$i];} |
if (@formats && $#formats) {$fmt=$formats[$i];} |
foreach my $element (@$ans) { |
my @answers; |
|
if (ref($ans) eq 'ARRAY') { |
|
@answers = (@{$ans}); |
|
} |
|
foreach my $element (@answers) { |
if ($fmt && $tag eq 'numericalresponse') { |
if ($fmt && $tag eq 'numericalresponse') { |
$fmt=~s/e/E/g; |
$fmt=~s/e/E/g; |
if ($unit=~/\$/) { $fmt="\$".$fmt; $unit=~s/\$//g; } |
if ($unit=~/\$/) { $fmt="\$".$fmt; $unit=~s/\$//g; } |
if ($unit=~/\,/) { $fmt="\,".$fmt; $unit=~s/\,//g; } |
if ($unit=~/\,/) { $fmt="\,".$fmt; $unit=~s/\,//g; } |
$element = &format_number($element,$fmt,$target, |
$element = &format_number($element,$fmt,$target, |
$safeeval); |
$safeeval); |
if ($fmt=~/\$/ && $unit!~/\$/) { $element=~s/\$//; } |
if ($fmt=~/\$/ && !$needsdollar) { $element=~s/\$//; } |
} |
} |
} |
} |
push(@fmt_ans,join(',',@$ans)); |
push(@fmt_ans,join(',',@answers)); |
} |
} |
my $response=\@fmt_ans; |
my $response=\@fmt_ans; |
|
|
Line 773 sub end_numericalresponse {
|
Line 784 sub end_numericalresponse {
|
! ($Apache::lonhomework::type eq 'exam' || |
! ($Apache::lonhomework::type eq 'exam' || |
lc($hideunit) eq "yes") ) { |
lc($hideunit) eq "yes") ) { |
my $cleanunit=$unit; |
my $cleanunit=$unit; |
$cleanunit=~s/\$\,//g; |
$cleanunit=~s/[\$,]//g; |
foreach my $ans (@fmt_ans) { |
foreach my $ans (@fmt_ans) { |
$ans.=" $cleanunit"; |
$ans.=" $cleanunit"; |
} |
} |
Line 790 sub end_numericalresponse {
|
Line 801 sub end_numericalresponse {
|
$tag,$parstack, |
$tag,$parstack, |
$safeeval,1); |
$safeeval,1); |
$error=&mt("Computer's answer is incorrect ([_1]).",'"'.join(', ',@$response).'"').' '; |
$error=&mt("Computer's answer is incorrect ([_1]).",'"'.join(', ',@$response).'"').' '; |
if ($sigline ne '') { |
if (($ad eq 'NO_UNIT') && $needsdollar) { |
|
$error.=&mt('The unit attribute includes [_1] but the answer format does not.','$').' '. |
|
&mt('Either remove the [_1] from the unit or prepend [_1] to the answer format.','$'); |
|
} elsif (($ad eq 'COMMA_FAIL') && $needscomma) { |
|
$error.=&mt('The unit attribute includes [_1] but the answer format does not.',',').' '. |
|
&mt('Either remove the [_1] from the unit or prepend [_1] to the answer format.',','); |
|
} elsif ($ad eq 'UNIT_INVALID_STUDENT') { |
|
$error.=&mt('Unable to interpret units. Computer reads units as "[_1]".',$msg).' '. |
|
&mt('The unit attribute in the numericalresponse item needs to be a supported physical unit.'); |
|
} elsif ($sigline ne '') { |
$error.=&mt('It is likely that the tolerance range [_1] or significant figures [_2] need to be adjusted.',$tolline,$sigline); |
$error.=&mt('It is likely that the tolerance range [_1] or significant figures [_2] need to be adjusted.',$tolline,$sigline); |
} else { |
} else { |
$error.=&mt('It is likely that the tolerance range [_1] needs to be adjusted.',$tolline); |
$error.=&mt('It is likely that the tolerance range [_1] needs to be adjusted.',$tolline); |
Line 891 sub get_table_sizes {
|
Line 911 sub get_table_sizes {
|
my $cell_width=0; |
my $cell_width=0; |
foreach my $member (@$rbubble_values) { |
foreach my $member (@$rbubble_values) { |
my $cell_width_real=0; |
my $cell_width_real=0; |
if ($member=~/(\+|-)?(\d*)\.?(\d*)\s*\$?\\times\s*10\^{(\+|-)?(\d+)}\$?/) { |
if ($member=~/(\+|-)?(\d*)\.?(\d*)\s*\$?\\times\s*10\^\{(\+|-)?(\d+)}\$?/) { |
$cell_width_real=(length($2)+length($3)+length($5)+7)*$scale; |
$cell_width_real=(length($2)+length($3)+length($5)+7)*$scale; |
} elsif ($member=~/(\d*)\.?(\d*)(E|e)(\+|-)?(\d*)/) { |
} elsif ($member=~/(\d*)\.?(\d*)(E|e)(\+|-)?(\d*)/) { |
$cell_width_real=(length($1)+length($2)+length($5)+9)*$scale; |
$cell_width_real=(length($1)+length($2)+length($5)+9)*$scale; |
Line 1045 sub make_numerical_bubbles {
|
Line 1065 sub make_numerical_bubbles {
|
&Math::Random::random_uniform_integer(1,1,10); |
&Math::Random::random_uniform_integer(1,1,10); |
} |
} |
for ($ind=0;$ind<$number_of_bubbles;$ind++) { |
for ($ind=0;$ind<$number_of_bubbles;$ind++) { |
$bubble_values[$ind] = $answerfactor*($factor**($power-$powers[$#powers-$ind])); |
my $exponent = $power-$powers[$#powers-$ind]; |
|
$bubble_values[$ind] = $answerfactor*($factor**$exponent); |
|
|
|
# If bubble is for correct answer (i.e., exponent = 0), and value |
|
# of $answerfactor * factor**$exponent is an integer with more than |
|
# 15 digits, assign $answerfactor itself as bubble value. |
|
# This prevents a "use fewer digits" issue on 64bit servers |
|
# when correct answer is >= 1e+16, and when correct bubble is A. |
|
|
|
if ($exponent == 0) { |
|
if ($bubble_values[$ind] =~ /^-?(\d+)$/) { |
|
if (length($1) > 15) { |
|
$bubble_values[$ind] = $answerfactor; |
|
} |
|
} |
|
} |
|
|
$bubble_display[$ind] = &format_number($bubble_values[$ind], |
$bubble_display[$ind] = &format_number($bubble_values[$ind], |
$format,$target,$safeeval); |
$format,$target,$safeeval); |
} |
} |