Forum archive 2000-2006

Gregg Klein - conditonal problem

Gregg Klein - conditonal problem

by Arnold Pizer -
Number of replies: 0
inactiveTopicconditonal problem topic started 10/7/2002; 11:19:12 AM
last post 10/7/2002; 1:25:44 PM
userGregg Klein - conditonal problem  blueArrow
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



<| Post or View Comments |>

userMichael Gage - Re: conditonal problem  blueArrow
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/

Conditional questions example

If f(x) = 17 x + 4, find f'( -7 ).





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;

If \( f(x) = $a1 x + $b1 \), find \( f'( $x1 ) \).
$BR $BR \{NAMED_ANS_RULE('first_answer',10) \}

$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
# 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
# and which you can also reach at

# 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

# 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.

$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) \}

$ans_eval2 = num_cmp($a2);

NAMED_ANS(SecondAnSwEr => $ans_eval2);


<| Post or View Comments |>