Forum archive 2000-2006

Stephen Corwin - + in answer evaluator code

Stephen Corwin - + in answer evaluator code

by Arnold Pizer -
Number of replies: 0
inactiveTopic+ in answer evaluator code topic started 10/14/2005; 9:45:40 AM
last post 10/14/2005; 11:36:31 AM
userStephen Corwin - + in answer evaluator code  blueArrow
10/14/2005; 9:45:40 AM (reads: 384, responses: 3)
Hi--

The code below, which defines an answer evaluator, doesn't work. The problem is the + signs. If I replace

    $ans =~ s/\s+//g

with

    $ans =~ s/ //g

and remove the + sign in the if test, everything is fine (except, of course, that then the answer I want from the students doesn't match what's in the if test). I fixed this particular problem by replacing the m/// by a substring test, but how do you program around it in general? And why does it happen? (I also tried $ans =~ s/\+/X/ which doesn't do anything either. None of these things results in an error message; the code just fails silently.)

Thanks again,

Steve

$anseval = sub {

     my $student_ans = shift;
     my $correct = 0;
     my $ans = $student_ans;

     $ans =~ s/\s+//g; # FAILS
     $ans =~ tr/[a-z]/[A-Z]/;
     if ($ans =~ /^P\+PRT$/ || $ans =~ /^P\(1\+RT\)$/) {$correct = 1;} # FAILS

     my $anshash = new AnswerHash();
     $anshash->{'score'} = $correct;
     $anshash->{'correct_ans'} = "P+Prt or P(1+rt)";
     $anshash->{'student_ans'} = $student_ans;
     $anshash->{'type'} = "SPC";

     return $anshash;

};

<| Post or View Comments |>


userBob Byerly - Re: + in answer evaluator code  blueArrow
10/14/2005; 10:53:41 AM (reads: 474, responses: 1)
I think you're being bitten by the redefinition of the perl escape character in the PG language. (This has happened to me too.) It should be ~~ (two tildes) instead of backslash.

Bob

<| Post or View Comments |>


userJohn Jones - Re: + in answer evaluator code  blueArrow
10/14/2005; 11:36:31 AM (reads: 470, responses: 0)
Hi,

My guess is that there might be simpler ways of coding this answer evaluator. For the most part, this seems to be a string checker ignoring case and whitespace. I think some version of str_cmp can handle that (or str_cmp with the right flags set). You could then use the pc evaluator to put two of them together as an "or".

Alternatively, you could code this with fun_cmp with variables P, r, and t. Then, "(1+rt)P", "P+rtP", and similar variations, would also be marked correct automatically. If you want to allow anything algebraically equivalent to the right answer, then fun_cmp would be the way to go.

John

<| Post or View Comments |>


userStephen Corwin - Re: + in answer evaluator code  blueArrow
10/14/2005; 1:59:13 PM (reads: 540, responses: 0)
Thanks, that was it.

<| Post or View Comments |>