WeBWorK Problems

A failed attempt to use Gavin LaRose's Sample Problem 2

A failed attempt to use Gavin LaRose's Sample Problem 2

by Kenneth Appel -
Number of replies: 1
I tried to emulate Gavin LaRose's Sample Problem 2. But the question was
apparently interpreted as using part2 twice (althougn the solutions worked
correctly. ) I do not know whether the difficulty arises from using two parts
which are both multiple choice or a missing separator of some sort. I can't
find such a separator in the sample problem.
The problem was correct when it only included Part 1.
Ken Appel

DOCUMENT(); # This should be the first executable line in the problem.
# "compoundProblem.pl",
# "unionLists.pl",

# set up for a multiple choice problem.
#Initialization for Part 1
$radio = new_multiple_choice();
$radio->qa("1. Write an inequality for the phrase: two more than three times a number is at most 40", "\(2m+3\le 40\)");
$radio->extra("\(3m+2\ge 40\)", "\(3m+2\le 40\)");
$radio->makeLast("\(2m+3\ge 40\)" );
#Initialization for Part 2
$a = random(2100,2900,100);
$radio = new_multiple_choice();
$radio->qa("2. John wants to buy a car. He has $DOLLAR$a in his bank account. He needs to pay $DOLLAR$b for insurance. How many dollars can John spend for the car
? ", "\(c\le $d\)");
$radio->extra("\(c \le $c\)", "\(c\ge $c\)");
$radio->makeLast("\(c\ge $d\)" );

\{ $radio->print_q() \}
\{ $radio->print_a() \}

\{ $radio->print_q() \}
\{ $radio->print_a() \}
ANS( radio_cmp( $radio->correct_ans() ) );
ANS( radio_cmp( $radio->correct_ans() ) );
If a number is at most 40 it can be less than 40 or equal to 40.$BR
If we use m for a number then three times the number is 3m
He must start by planning to use $DOLLAR$b from his bank account to pay for
insurance. This will leave $DOLLAR$d which he can spend on the car But
he does not have to spend all of that.

In reply to Kenneth Appel

Re: A failed attempt to use Gavin LaRose's Sample Problem 2

by Davide Cervone -
You have used the same variable ($radio) for both parts, and so when you use it in the second part, it wipes out the value from the first part. Since you don't print the text of the first part of set up its answer checkers until the end, you have lost that data when you initialize the second part.

I'd put the text of part 1 and its answer checkers right after initializing it, and before starting on part 2. I know Gavin's sample doesn't work that way, but I think that makes more sense, and avoid this type of error.

In the lastest version of PG there is now a BEGIN_SOLUTION/END_SOLUTION block that will make it easier (or at least prettier) to enter your solutions.