WeBWorK Problems

Randomization of questions - using PGML and popUps

Randomization of questions - using PGML and popUps

by Sergio Chaves -
Number of replies: 2

Hello all,

I am just starting with the creation of Webwork problems. I have written the following problem

DOCUMENT();        # This should be the first executable line in the problem.

loadMacros(
  "PGstandard.pl",
  "PGchoicemacros.pl",
  "PGunion.pl",
  "choiceUtils.pl",
  "PGcourse.pl",
  "PGML.pl",
  "parserPopUp.pl"
);

TEXT(beginproblem());


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

Context()->strings->add(Tautology => {}, Contradiction => {}, Neither => {});

$ans_a = PopUp(
["?", "True","False"],
1,
);

$ans_b = PopUp(
["?", "True","False"],
2,
);


BEGIN_PGML

Determine which of the following statements are true or false:

1. This statement is True.
Answer: [_]{$ans_a}

1. This statement is False
Answer: [_]{$ans_b}

END_PGML


ENDDOCUMENT(); 

I would like to modify this problem so the student will only get one of the 2 questions at random (eventually I would like to have n questions in this problem and select k at random)

I haven't been able to find anything  in the documentation or the OPL related on how to implement this using popUps questions. Any help is very much appreciated.

In reply to Sergio Chaves

Re: Randomization of questions - using PGML and popUps

by Alex Jordan -
Here are some PG/Perl tricks that can help with this.

DOCUMENT();

loadMacros(
"PGstandard.pl",
"PGchoicemacros.pl",
"MathObjects.pl",
"PGML.pl",
"parserPopUp.pl",
"PGcourse.pl",
);

TEXT(beginproblem());

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

# For convenience:
$true = PopUp(['?','True','False'],1);
$false = PopUp(['?','True','False'],2);

# Make a Perl array where each entry is an array reference with statement and answer.
# The statements can use PGML syntax if you use the double stars below in the statement.
@questions = (
['[`1+1=2`]', $true],
['This is true.', $true],
['This is _not_ true.', $false],
);

# Choose one of them randomly
$question = list_random(@questions);
($statement,$answer) = @{$question};


BEGIN_PGML

[$statement]**
[_]{$answer}

END_PGML


# To use more than one, take a "slice" of the @questions array.
# Since PGchoice,acros.pl is loaded, we can use NchooseK.
@usethese = (@questions)[NchooseK(3,2)];
@statement = map{$_->[0]}(@usethese);
@answer = map{$_->[1]}(@usethese);

BEGIN_PGML

1. [$statement[0]]**
[_]{$answer[0]}

1. [$statement[1]]**
[_]{$answer[1]}

END_PGML

ENDDOCUMENT();

In reply to Alex Jordan

Re: Randomization of questions - using PGML and popUps

by Sergio Chaves -

Thank you, very much appreciated! This is exactly what I was looking for.