[LON-CAPA-cvs] cvs: loncom /homework/caparesponse caparesponse.pm

www lon-capa-cvs-allow@mail.lon-capa.org
Thu, 06 Mar 2008 02:48:23 -0000


www		Wed Mar  5 21:48:23 2008 EDT

  Modified files:              
    /loncom/homework/caparesponse	caparesponse.pm 
  Log:
  Bug #2698: produce random instead of complete garbage if the exam answer
  is zero
  
  
Index: loncom/homework/caparesponse/caparesponse.pm
diff -u loncom/homework/caparesponse/caparesponse.pm:1.221 loncom/homework/caparesponse/caparesponse.pm:1.222
--- loncom/homework/caparesponse/caparesponse.pm:1.221	Fri Feb  1 18:00:56 2008
+++ loncom/homework/caparesponse/caparesponse.pm	Wed Mar  5 21:48:23 2008
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # caparesponse definition
 #
-# $Id: caparesponse.pm,v 1.221 2008/02/01 23:00:56 raeburn Exp $
+# $Id: caparesponse.pm,v 1.222 2008/03/06 02:48:23 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -988,13 +988,23 @@
     $ind=&Math::Random::random_uniform_integer(1,0,$#factors);
     my $factor = $factors[$ind];
     my @bubble_display;
+    my $answerfactor=$answer;
+    if ($answer==0) { 
+       $answerfactor=&Math::Random::random_uniform_integer(1,1,100)/
+                     &Math::Random::random_uniform_integer(1,1,10);
+    }
     for ($ind=0;$ind<$number_of_bubbles;$ind++) {
-	$bubble_values[$ind] = $answer*($factor**($power-$powers[$#powers-$ind]));
+	$bubble_values[$ind] = $answerfactor*($factor**($power-$powers[$#powers-$ind]));
 	$bubble_display[$ind] = &format_number($bubble_values[$ind],
 					       $format,$target,$safeeval);
-
     }
     my $correct = $alphabet[$number_of_bubbles-$power];
+    if ($answer==0) {
+       $correct='A';
+       $bubble_values[0]=0;
+       $bubble_display[0] = &format_number($bubble_values[0],
+                                           $format,$target,$safeeval);
+    }
     &Math::Random::random_set_seed(@oldseed);
     return (\@bubble_values,\@bubble_display,$correct);
 }