[LON-CAPA-cvs] cvs: loncom /homework default_homework.lcpm

www lon-capa-cvs-allow@mail.lon-capa.org
Thu, 06 Mar 2008 14:04:10 -0000


www		Thu Mar  6 09:04:10 2008 EDT

  Modified files:              
    /loncom/homework	default_homework.lcpm 
  Log:
  Bug #1967: accept percentages as numerical answers, such as "80% c" for
  eighty percent speed of light.
  
  
Index: loncom/homework/default_homework.lcpm
diff -u loncom/homework/default_homework.lcpm:1.131 loncom/homework/default_homework.lcpm:1.132
--- loncom/homework/default_homework.lcpm:1.131	Wed Mar  5 21:20:05 2008
+++ loncom/homework/default_homework.lcpm	Thu Mar  6 09:04:09 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # used by lonxml::xmlparse() as input variable $safeinit to Apache::run::run()
 #
-# $Id: default_homework.lcpm,v 1.131 2008/03/06 02:20:05 www Exp $
+# $Id: default_homework.lcpm,v 1.132 2008/03/06 14:04:09 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -311,7 +311,7 @@
     if ($type eq '' || $type eq 'float') {
 	#for numerical problems split off the unit
 #	if ( $responses->[0][-1]=~ /(.*[^\s])\s+([^\s]+)/ ) {
-        if ( $responses->[0][-1]=~ /^([\d\.\,\s\$]*(?:(?:[xX\*]10[\^\*]*|[eE]*)[\+\-]*\d*)*(?:^|\S)\d+)([\$\s\w\^\*\/\(\)\+\-]*[^\d\.][\$\s\w\^\*\/\(\)\+\-]*)$/ ) {
+        if ( $responses->[0][-1]=~ /^([\d\.\,\s\$]*(?:(?:[xX\*]10[\^\*]*|[eE]*)[\+\-]*\d*)*(?:^|\S)\d+)([\$\s\w\^\*\/\(\)\+\-]*[^\d\.\s\,][\$\s\w\^\*\/\(\)\+\-]*)$/ ) {
 	    $responses->[0][-1]=$1;
 	    $unit=&capa_formula_fix($2);
             &LONCAPA_INTERNAL_DEBUG("Found unit :$unit:");
@@ -322,8 +322,14 @@
     if ($unit ne '') {
 	foreach my $response (@$responses) {
 	    foreach my $element (@$response) {	
-                $element =~ s/\s//g;    
-		$element .= " $unit";
+                $element =~ s/\s//g;
+                my $appendunit=$unit;
+                if ($unit=~/\%/) {
+                   $element=$element/100;
+                   $appendunit=~s/\%//;
+                }    
+		$element .= " $appendunit";
+                &LONCAPA_INTERNAL_DEBUG("Made response element :$element:");
 	    }
 	}
     }