## Forum archive 2000-2006

### Gregg Klein - conditonal problem ### Gregg Klein - conditonal problem

by Arnold Pizer -
Number of replies: 0 conditonal problem topic started 10/7/2002; 11:19:12 AMlast post 10/7/2002; 1:25:44 PM Gregg Klein - conditonal problem 10/7/2002; 11:19:12 AM (reads: 782, responses: 1) I'm still looking for an easy template to follow for a conditonal problem. If anyone has source code please respond. My goal is to have a problem that I can use in a lab setting where I walk students through a new concept that has multi-steps. I want the next question (i.e. next step) to be asked if first question is answered correctly. I would to be able to have several steps in the problem, not just two Thanks, Gregg. <| Post or View Comments |> Michael Gage - Re: conditonal problem 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
 Conditional questions example If , find .

WARNINGS
µ¦å{h­

DOCUMENT();loadMacros(        "PGbasicmacros.pl",        "PGchoicemacros.pl",        "PGanswermacros.pl");TEXT(beginproblem(), $BR,$BBOLD, "Conditional questions example", $EBOLD,$BR,$BR);$showPartialCorrectAnswers = 1;$a1 = random(3,25,1);$b1 = random(2,27,1);$x1 = random(-11,11,1);$a2 = $a1+5;BEGIN_TEXTIf $$f(x) = a1 x + b1$$, find $$f'( x1 )$$.$BR $BR \{NAMED_ANS_RULE('first_answer',10) \}$BREND_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} ) { # WATCH OUT!!: BEGIN_TEXT and END_TEXT have to be on lines by # themselves and left justified!!! This means you can't indent # this section as you might want to. The placement of BEGIN_TEXT # and END_TEXT is one of the very few formatting requirements in # the PG language.BEGIN_TEXT$PAR Right! Now                try the second part of the problem: $PAR$HR                If $$f(x) = a2 x + \{b1+5\}$$, find $$f'( x)$$.                $BR$BR \{ NAMED_ANS_RULE('SecondAnSwEr',10) \}                $BREND_TEXT$ans_eval2 = num_cmp($a2); NAMED_ANS(SecondAnSwEr =>$ans_eval2); }  ENDDOCUMENT();

<| Post or View Comments |>