topic started 10/7/2002; 11:19:12 AM last post 10/7/2002; 1:25:44 PM |
|
10/7/2002; 1:25:44 PM (reads: 1070, responses: 0) |
|
Hi Gregg, Does this example work for you? You can nest the if statements, so that you can ask ask as many parts as you like. --Mike
(1 pt) rochesterLibrary/setMAAtutorial/conditionalquestionexample.pg
WARNINGS µ¦å{h<p> </p><pre>DOCUMENT();<br />loadMacros(<br /> "PGbasicmacros.pl",<br /> "PGchoicemacros.pl",<br /> "PGanswermacros.pl"<br />);<br />TEXT(beginproblem(), $BR,$BBOLD, "Conditional questions example", $EBOLD, $BR,$BR);<br />$showPartialCorrectAnswers = 1;<br /><br />$a1 = random(3,25,1);<br />$b1 = random(2,27,1);<br />$x1 = random(-11,11,1);<br />$a2 = $a1+5;<br /><br />BEGIN_TEXT<br />If \( f(x) = $a1 x + $b1 \), find \( f'( $x1 ) \).<br />$BR $BR \{NAMED_ANS_RULE('first_answer',10) \} $BR END_TEXT $ans_eval1 = num_cmp($a1); NAMED_ANS(first_answer => $ans_eval1); # Using named answers allows for more control. Any unique label can be # used for an answer. # (see http://webwork.math.rochester.edu/docs/docs/pglanguage/pgreference/managinganswers.html # for more details on answer evaluator formats and on naming answers # so that you can refer to them later. Look also at the pod documentation in # PG.pl and PGbasicmacros.pl which you can also reach at # http://webwork.math.rochester.edu/docs/techdescription/pglanguage/index.html) # Check to see that the first answer was answered correctly. If it was then we # will ask further questions. $first_Answer = $inputs_ref->{first_answer} # We need to know what the answer # was named. $rh_ans_hash = $ans_eval1->evaluate($first_Answer); # warn pretty_print($rh_ans_hash); # this is useful technique for finding errors. # When uncommented it prints out the contents of # the ans_hash for debugging # The output of each answer evaluator consists of a single %ans_hash with (at # least) these entries: # $ans_hash{score} -- a number between 0 and 1 # $ans_hash{correct_ans} -- The correct answer, as supplied by the instructor # $ans_hash{student_ans} -- This is the student's answer # $ans_hash{ans_message} -- Any error message, or hint provided by # the answer evaluator. # $ans_hash{type} -- A string indicating the type of answer evaluator. # -- Some examples: # 'number_with_units' # 'function' # 'frac_number' # 'arith_number' # For more details see # http://webwork.math.rochester.edu/docs/docs/pglanguage/pgreference/answerhashdataype.html # If they get the first answer right, then we'll ask a second part to the # question ... if (1 == $rh_ans_hash->{score} ) {<br /><br /> # WATCH OUT!!: BEGIN_TEXT and END_TEXT have to be on lines by<br /> # themselves and left justified!!! This means you can't indent<br /> # this section as you might want to. The placement of BEGIN_TEXT<br /> # and END_TEXT is one of the very few formatting requirements in<br /> # the PG language.<br /><br />BEGIN_TEXT<br /> $PAR Right! Now<br /> try the second part of the problem: $PAR $HR<br /> If \( f(x) = $a2 x + \{$b1+5\} \), find \( f'( x) \). $BR $BR \{ NAMED_ANS_RULE('SecondAnSwEr',10) \} $BR END_TEXT $ans_eval2 = num_cmp($a2); NAMED_ANS(SecondAnSwEr => $ans_eval2); } ENDDOCUMENT(); |