PopUpListsLong
This problem has been replaced with a newer version of this problem
Pop-Up Lists For Many Questions With Common Answers
This is the PG code for using pop-up menus displaying multiple questions with a common set of possible answers, such as a list of true or false questions or a list of multiple choice questions in which the choices are the same for each question.
- Example 1: (Recommended) The newer method.
- Example 2: (Not Recommended) The older method, which perhaps offers more options for customization.
Example 1: This code shows how to create lengthy pop-up lists in a WeBWorK problem using newer constructs. This example comes from /Library/Rochester/setMAAtutorial/popuplistexample.pg and you are also encouraged to look at Library/Rochester/setMAAtutorial/prob4.pg
PG problem file | Explanation |
---|---|
DOCUMENT(); loadMacros( "PGstandard.pl", "PGchoicemacros.pl", #"PGgraders.pl", ); TEXT(beginproblem()); |
Initialization: to use these pop-up lists, load |
# Create and use pop up lists $tf = new_select_list(); $tf->rf_print_q(~~&pop_up_list_print_q); # Specify choices presented to students $tf->ra_pop_up_list( [ No_answer => "?", "T"=>"True", "F"=>"False"] ); # Questions and answers $tf -> qa ( "All continuous functions are differentiable.", "F", "All differentiable functions are continuous.", "T", "All polynomials are differentiable.", "T", "All functions with positive derivatives " . "are increasing.", "T", ); # How many questions to use $tf->choose(3); |
Setup: We make a new select list $tf that "contains" the select list object. Then, the line specifying the "printq" function changes the printing mechanism of the object to use a pop-up list instead of an answer rule.
The line specifying "ra_pop_up_list" gives a list of the choices that are presented for each question. The format of the list reference is
Next, we specify some questions and their answers, as a comma-separated list of question and answer pairs. At the end, we specify how many of these to display to the students.
(Note that we've broken some of these questions into pieces to avoid long lines on this web page, by using string concatenation. In Perl, the period concatenates strings: thus, |
BEGIN_TEXT Are the following statements true or false? $BR \{ $tf-> print_q \} END_TEXT |
Main Text: You may modify the instructions if you want. You should explicitly say what all of the possible answers are so that students who have a pdf or paper copy can work directly from it. |
install_problem_grader(~~&std_problem_grader); $showPartialCorrectAnswers = 0; ANS(str_cmp($tf->ra_correct_ans)); ENDDOCUMENT(); |
Answer Evaluation:
Install the standard problem grader
Instead of having an all-or-nothing grader, it is possible to have an incremental weighted grader that will give students a custom score for having a certain number of answers correct. For example, suppose that we have 8 questions in install_problem_grader(~~&custom_problem_grader_fluid); $ENV{'grader_numright'} = [2,5,7,8]; $ENV{'grader_scores'} = [0.1,0.6,0.8,1]; $ENV{'grader_message'} = "You can earn " . "10% partial credit for 2 - 4 correct answers, " . "60% partial credit for 5 - 6 correct answers, and " . "80% partial credit for 7 correct answers."; $showPartialCorrectAnswers = 0; ANS(str_cmp($tf->ra_correct_ans)); ENDDOCUMENT(); Notice that the last entry "8" in |
Example 2: This code shows how to create lengthy pop-up lists in a WeBWorK problem using older-style answer checkers, some deprecated elements such as shuffle, and elementary bits of code to build things from scratch.
PG problem file | Explanation |
---|---|
DOCUMENT(); loadMacros( "PG.pl", "PGbasicmacros.pl", "PGchoicemacros.pl", "PGanswermacros.pl", "PGcourse.pl", ); TEXT(beginproblem()); |
Initialization: We need to include several macro files. |
$a = random(1,5,1); @questions_and_answers = ( "Larry is one of the three stooges.", "True", "Gandalf is one of the three stooges.", "False", "\(\pi + $a\) is rational.", "False", ); @choices = ("True", "False"); |
Set-up: Create an array in which questions alternate with answers. Answers may be any string. For true or false questions, this is the only part of the example that needs to be modified. We added a randomized element to the question about pi. Do not use the names $numq, $qn, or $qns to avoid conflicts with the code below. |
BEGIN_TEXT Are the following statements true or false? $BR $BR END_TEXT |
Instructions and Question for all parts: You may modify the instructions if you want. You should explicitly say what all of the possible answers are so that students who have a pdf or a paper copy can work directly from it. |
# $numq = number of questions $numq = scalar(@questions_and_answers)/2; @shuffle = shuffle($numq); @abc = (a..z); # or (A..Z) or (1..$numq) # $qn = question number for $qn (0..$numq-1) { # $qns = question number shuffled $qns = $shuffle[$qn]; BEGIN_TEXT @abc[$qn]. \{ pop_up_list(['?', @choices]) \} $SPACE $questions_and_answers[2*$qns] $BR$BR END_TEXT ANS(str_cmp($questions_and_answers[2*$qns+1], filters=>["trim_whitespace","compress_whitespace"])); } install_problem_grader(~~&std_problem_grader); $showPartialCorrectAnswers = 0; ENDDOCUMENT(); |
Main Text and Answer Evaluation: You should not need to modify this section at all. We shuffle the order of the questions and use a for loop to generate one question and one answer evaluator for each pair in the array @questions_and_answers. Install the |