WeBWorK Main Forum

How have lists of arbitrary string answers?

How have lists of arbitrary string answers?

by Christian Seberino -
Number of replies: 3
The question below expects 3 strings answers.....the letters l, t and r.
It keeps marking it wrong.  How set up the PGML problem so that
it allows lists of string answers?

Thanks,

Chris






DOCUMENT();
loadMacros(
  "MathObjects.pl",
  "PGstandard.pl",
  "PGML.pl",
  "PGcourse.pl",
  "parserNumberWithUnits.pl",
  "contextArbitraryString.pl",
  "parserMultiAnswer.pl",
  "parserPopUp.pl",
);
TEXT(beginproblem());
$showPartialCorrectAnswers = 1;
######################################################################

Context("ArbitraryString");

@string_answers_t = ("t");
$strings_t = Compute("")->cmp(checker => sub {
        my ($temp1, $response, $temp2) = @_;
        $response =~ s/^~~s+|~~s+$//g;
        $response = lc($response);
        foreach (@string_answers_t) {
                if ($response eq lc($_)) {
                        return 1;
                }
        }

        return 0;
});

@string_answers_r = ("r");
$strings_r = Compute("")->cmp(checker => sub {
        my ($temp1, $response, $temp2) = @_;
        $response =~ s/^~~s+|~~s+$//g;
        $response = lc($response);
        foreach (@string_answers_r) {
                if ($response eq lc($_)) {
                        return 1;
                }
        }

        return 0;
});

@string_answers_l = ("l");
$strings_l = Compute("")->cmp(checker => sub {
        my ($temp1, $response, $temp2) = @_;
        $response =~ s/^~~s+|~~s+$//g;
        $response = lc($response);
        foreach (@string_answers_l) {
                if ($response eq lc($_)) {
                        return 1;
                }
        }

        return 0;
});



BEGIN_PGML
What are all the *consonants* in the word 'letter'?

[________________________]{List($strings_l, $strings_t, $strings_r)}
END_PGML

######################################################################
ENDDOCUMENT();

In reply to Christian Seberino

Re: How have lists of arbitrary string answers?

by Hedley Pinsent -
This is how I would approach it (today).
Still a bit rough.
hp


##DESCRIPTION

########################################################################

DOCUMENT();

loadMacros(
"PGstandard.pl", # Standard macros for PG language
"MathObjects.pl",

);

########################################################################

TEXT(beginproblem());

$showPartialCorrectAnswers = 1;

########################################################################
# Adapted from "modifying Contexts (Advanced)


Context()->{pattern}{number} = '[a-zA-Z]+';
# Context()->{pattern}{signedNumber} = '[a-zA-Z]+';
Context()->flags->set(NumberCheck => sub {
my $self = shift; # the Number object
$self->{value} = ord (lc($self->{value_string})); # convert hex to decimal via perl hex() function
$self->{isOne} = ($self->{value} == 1); # set marker indicating if the value is 1
$self->{isZero} = ($self->{value} == 0); # set marker indicating if the value is 0
});
Context()->update;

$answer = List(Compute ("C,T,L"));

Context()->texStrings;
BEGIN_TEXT

The consonants in cattle are: \{ ans_rule(10) \}

END_TEXT

Context()->normalStrings;

########################################################################

ANS($answer->cmp($answer));
ENDDOCUMENT();
In reply to Hedley Pinsent

Re: How have lists of arbitrary string answers?

by Christian Seberino -
Thanks.  My example was for single letter answer but I actually
need something that works for 3 or more answers that are words.

So can I assume there is no standard code for doing a list
of strings?  It is necessary to roll something custom for this purpose?

cs
In reply to Christian Seberino

Re: How have lists of arbitrary string answers?

by Christian Seberino -
I guess in the custom grader for a single string I can do the processing.

Yea.  I think that is the most flexible and will work.

Thanks for the help.

cs