From WeBWorK_wiki
Revision as of 10:54, 19 October 2009 by Pearson (talk | contribs) (New page: <h2>Pop-Up Lists That Are Long: PG Code Snippet</h2> <p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> <em>This code snippet shows the PG code to create lengthy pop...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Pop-Up Lists That Are Long: PG Code Snippet

This code snippet shows the PG code to create lengthy pop-up lists in a WeBWorK problem. Note that these are insertions, not a complete PG file. This code will have to be incorporated into the problem file on which you are working.

Problem Techniques Index

PG problem file Explanation



Initialization: We need to include the PGchoicemacros.pl macro file.

@questions_and_answers = (
"Larry is one of the three stooges.","True",
"\(\pi\) is rational","False",
"Gandalf is one of the three stooges.","False"

Set-up: An array in which questions alternate with answers.


Are the following statements true or false? 


Instructions and Question for all parts: self explanatory.

$n = scalar(@questions_and_answers)/2;
@shuffle = shuffle($n);
@abc = (a..z);

for $jj (0..$n-1) {
$j = $shuffle[$jj];
@abc[$jj]. \{ pop_up_list(['?', 'True', 'False']) \} $SPACE 
ANS(str_cmp($questions_and_answers[2*$j+1], filters=>["trim_whitespace","compress_whitespace"]));


Main Text and Answer Evaluation: Shuffle the order of the questions, then use a for loop to generate one question and answer for each pair in the array @questions_and_answers.

Problem Techniques Index