Difference between revisions of "MatchingProblems"
m (1 revision: import all default namespace pages from old wiki) |
(add historical tag and give links to newer problems.) |
||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
+ | |||
+ | {{historical}} |
||
+ | |||
+ | <p style="font-size: 120%;font-weight:bold">This problem has been replaced with many other problems:</p> |
||
+ | * [https://openwebwork.github.io/pg-docs/sample-problems/Misc/Matching.html Original matching problem] |
||
+ | * [https://openwebwork.github.io/pg-docs/sample-problems/Algebra/MatchingAlt.html A newer matching problem] |
||
+ | |||
<h2>Matching Problems</h2> |
<h2>Matching Problems</h2> |
||
Line 171: | Line 178: | ||
The answer to the second question is |
The answer to the second question is |
||
$correctAns[1], because |
$correctAns[1], because |
||
− | explanations[$askedQuestions[1]]. |
+ | $explanations[$askedQuestions[1]]. |
END_SOLUTION |
END_SOLUTION |
Latest revision as of 08:15, 16 July 2023
This problem has been replaced with many other problems:
Matching Problems
This shows the essential PG code to set up a matching problem.
PG problem file | Explanation |
---|---|
DOCUMENT(); loadMacros( "PG.pl", "PGbasicmacros.pl", "PGchoicemacros.pl", "PGanswermacros.pl", "unionTables.pl", ); TEXT(beginproblem()); |
Initialization: All of these macros are required, except for |
$ml = new_match_list(); $ml->qa( "What's the answer to question 1?", "Ans 1", "What's the answer to question 2?", "Ans 2", "What's the answer to question 3?", "Ans 3" ); # use pop-up-lists $ml->rf_print_q(~~&pop_up_list_print_q); # you may need to add more letters D=>"D", etc. $ml->ra_pop_up_list([No_answer=>"?",A=>"A",B=>"B",C=>"C"]); $ml->choose(3); # to add extra answers that show up in the # matching list, we would uncomment # (remove the leading "# " from) the two # lines below: # $ml->extra("Extra Ans 1", "Extra Ans 2"); # $ml->choose_extra(2); $ml->makeLast("None of the above"); |
Setup:
We need make no changes to the description or initialization sections of the problem. In the problem set-up section, we define the matching list object by initializing it with
We can then select a subset of the matching problems to display to any given student by using the
Finally, we can also add an extra answer or answers at the end of the matching list by calling |
BEGIN_TEXT \{ $ml->print_q() \} $BR \{ $ml->print_a() \} END_TEXT |
Main Text: We then insert the matching list questions and answers into the problem text section of the problem.
To display the list of questions and answers side-by-side, in the initialization section load the Union macros with BEGIN_TEXT \{ ColumnMatchTable($ml) \} END_TEXT or BEGIN_TEXT \{ColumnTable( $PAR.$ml->print_q.$PAR, $ml->print_a, indent => 0, separation => 30, valign => "TOP" )\} $PAR END_TEXT |
# no credit until all answers are correct install_problem_grader(~~&std_problem_grader); $showPartialCorrectAnswers = 0; ANS( str_cmp( $ml->ra_correct_ans ) ); # the remainder of the code is included to # provide a sensible solution for the # student. # the answers to the questions that were # asked, in order, are @correctAns = @{$ml->ra_correct_ans}; # the following becomes necessary if we want # to figure out what questions were asked # so that we can give explanations for # them. # it's useful to define an array of # explanations that correspond to the # list of questions we might have asked @explanations = ( "explanation for question 1", "explanation for question 2", "explanation for question 3" ); # then find the questions that were asked @askedQuestions = (); foreach $q ( @{$ml->selected_q} ) { $i = 0; foreach $mq ( @{$ml->questions} ) { if ( $q eq $mq ) { push(@askedQuestions, $i); last; } $i++; } } # now we know which questions were asked, # and can print the corresponding # explanations for the solution #SOLUTION(EV3(<<'END_SOLUTION')); BEGIN_SOLUTION $PAR SOLUTION $PAR The answer to the first question is $correctAns[0], because $explanations[$askedQuestions[0]]. $PAR The answer to the second question is $correctAns[1], because $explanations[$askedQuestions[1]]. END_SOLUTION ENDDOCUMENT(); |
Answer evaluation and solution:
The correct answers are most easily graded using the old-style answer evaluator
We can get a list of the answers the student had to answer by looking at the array reference found from One way to do this is to use the list of questions that were asked to figure out which of the questions we could have asked showed up in the problem. Then we can show the corresponding explanations in the solution. To find the answers that were asked, we go through the questions that were asked and compare them with each of the questions that we could have asked, to see which is which. In this example we then save the index of the question and use that to print out the correct explanation. |