For the sake of answer checking, I used the command uc() perl command to convert the student answer array to upper case letters. However, if lower case letters are entered, lower case letters are shown the preview table, see below
I
would like to change the formatting of the student answer so that even
if they enter lower case letters, upper case letters are show in the
Answer Preview column (Entered column also would be nice).
With the parserMultiAnswer.pl , I know can feed a sprintf-style string to format => string and tex_format => string, but I can't find command for sprintf that affects the case of the string (I'm new at this). I've pasted my code below.
##DESCRIPTION
## Give an example of a derangement.
##ENDDESCRIPTION
##KEYWORDS('counting', 'inclusion exclusion', 'derangements')
## DBsubject('Combinatorics')
## DBchapter('Counting')
## DBsection('Inclusion/exclusion')
## Level('2')
## Date('01/30/2023')
## Author('Cynthia Loten')
## Institution('University of the Fraser Valley')
## TitleText1('Discrete and Combinatorial Mathematics')
## EditionText1('5')
## AuthorText1('Grimaldi')
## Section1('8.3')
########################################################################
DOCUMENT();
loadMacros(
"PGstandard.pl", # Standard macros for PG language
"MathObjects.pl",
"PGML.pl",
"PGchoicemacros.pl", # NchooseK defined here
"parserMultiAnswer.pl",
"PGcourse.pl", # Customization file for the course
);
# Print problem number and point value (weight) for the problem
TEXT(beginproblem());
# Show which answers are correct and which ones are incorrect, set to 0 for no information
$showPartialCorrectAnswers = 1;
##############################################################
#
# Setup
#
#
Context("Numeric");
@letters = ('A'..'Z');
$num_letters = 6; #randomize later??
@slice = NchooseK($#letters,$num_letters);
@my_letters = @letters[@slice];
$my_letters_string = join "", @my_letters;
foreach my $k (0..$num_letters-1) {
Context()->strings->add($my_letters[$k] =>{});
};
#################### question 1
@slice_der = NchooseK($num_letters,$num_letters);
@derangement = @my_letters[@slice_der];
foreach my $i (0..$num_letters-2) {
if ($derangement[$i] eq $my_letters[$i] ) { #swap with letter on the right
my $temp = $derangement[$i];
$derangement[$i] =$derangement[$i+1] ;
$derangement[$i+1] = $temp;
};
};
if ($derangement[-1] eq $my_letters[-1]) {
my $temp = $derangement[-1];
$derangement[-1] =$derangement[0] ;
$derangement[0] = $temp;
};
$der_string = join "", @derangement;
$multi_ans = MultiAnswer (@derangement) -> with (
singleResult => 1, ## entered answers on the same line in view table
separator => ' ' , tex_separator => '\hbox { }', ## text between two answers in view table
checker => sub{
my $correct= shift; my $student = shift;
@cor_der = @{$correct};
@stu_der = @{$student};
foreach my $i (0..$num_letters-1) {
$stu_der[$i] = uc($stu_der[$i]); # convert student answer to upper case if not
}
$stu_der_string = join "",@stu_der;
Value::Error("Repeated letters detected") if ($stu_der_string =~ /([a-zA-Z])~~1/ );
foreach my $i (0..$num_letters-1) {
if ($my_letters[$i] eq $stu_der[$i]) {
$multi_ans -> setMessage($i+1, "$stu_der[$i] in original spot");
return 0;
};
};
return 1;
},
);
##############################################################
#
# Text
#
#
BEGIN_PGML
All questions are about the following ordering of letters:[:quad :] [$my_letters_string]
a. Give a derangement of the original ordering. Enter one letter in each of the blanks.
[_]{$multi_ans} [_]{$multi_ans} [_]{$multi_ans} [_]{$multi_ans} [_]{$multi_ans} [_]{$multi_ans}
a. Removed
a. Removed
END_PGML
##############################################################
#
# Hints
#
#
$showHint = 2; # default is 2?
BEGIN_PGML
If you don't get this in [$showHint] tries, you can get a hint.
END_PGML
BEGIN_PGML_HINT
A derangement is a particular type of arrangement (permutation). Check your definitions!
END_PGML_HINT
##############################################################
#
# Solutions
#
#
BEGIN_PGML_SOLUTION
A derangement is a permutation where no object is in its original spot.
There is more than one correct answer for all 3 questions.
END_PGML_SOLUTION
ENDDOCUMENT();