Forum archive 2000-2006

Carl F. Letsche - Using submitted values within a problem

Carl F. Letsche - Using submitted values within a problem

by Arnold Pizer -
Number of replies: 0
inactiveTopicUsing submitted values within a problem topic started 10/18/2001; 1:50:51 PM
last post 10/25/2001; 3:50:17 PM
userCarl F. Letsche - Using submitted values within a problem  blueArrow
10/18/2001; 1:50:51 PM (reads: 1050, responses: 3)
Under an *old* version of WeBWorK, I unknowingly exploited what was apparently a bug that's since been fixed. I'm wondering how to do it with the new system. I'll describe what I did, and include the old problem at the end, for analysis.

Basically, I grabbed the strings submitted in the answer slot on the web page, then used 'eval' to make the strings into numerical values that were then used in the problem to compute whether the pair of answers were correct - each answer depended on the other (the objective was to find values for a and r so that the geometric series a*r^n converged to a random value).

How can i do this now? I tried tapping into the answer hash, but it's non-existant until the answer evaluator runs, and the answer evaluator needs the values...

Here's the original problem; (just trying to make it readable!)

##Description
##KEYWORDS('series', 'geometric')
##Find a geometric series converging to a given value
##enddescription



loadMacros(
PG.pl,
PGbasicmacros.pl,
PGchoicemacros.pl,
PGanswermacros.pl
);



$showPartialCorrectAnswers = 1;



&DOCUMENT;
TEXT(&beginproblem);



$b = non_zero_random(-20,20);



TEXT(EV2(<<EOT));



Find nonzero values of (a) and (r) so that the sequence
\[ sum_{n=0}^\infty a r^n \]
converges to $b.
$BR $BR



\(a=\)\{ans_rule(5) \}
$BR



\(r=\)\{ans_rule(5)\}
$BR
EOT



$a1=@submittedAnswers[0]; ## this grabs the strings they submitted
$r1=@submittedAnswers[1];



$a=eval($a1); ## this converts those strings into numeric values to compute with
$r=eval($r1);



if (($r <= -1) or ($r >= 1)) {
&ANS(std_num_cmp_list(.01,"",$b*(1-($r)),0));
} else {
if ($r==0) {
&ANS(std_num_cmp_list(.01,"",$b*(1-($r)),1));
} else {
&ANS(std_num_cmp_list(.01,"",$b*(1-($r)),1-($a/$b)));
}
}




&ENDDOCUMENT

<| Post or View Comments |>


userGavin LaRose - Re: Using submitted values within a problem  blueArrow
10/19/2001; 8:08:00 AM (reads: 1281, responses: 0)
This sounds like something Zig addressed in a previous thread: http://webhost.math.rochester.edu/webworkdocs/discuss/msgReader$422 might be helpful.

If not, I'm sure someone will come up with a better answer...

Gavin

<| Post or View Comments |>


userZbigniew Fiedorowicz - Re: Using submitted values within a problem  blueArrow
10/19/2001; 9:47:22 AM (reads: 1260, responses: 1)
There was a followup discussion on the same topic in another thread:

http://webhost.math.rochester.edu/webworkdocs/discuss/msgReader$467

Zig

<| Post or View Comments |>


userBill Ziemer - Re: Using submitted values within a problem  blueArrow
10/25/2001; 3:50:17 PM (reads: 1466, responses: 0)
The error "use of uninitialized string..." will appear, and precreation will complain as well since variables of the form $inputs_ref->{first_answer}; haven't been set by the webserver yet. Simple fix, put: $inputs_ref->{first_answer}='' unless defined $inputs_ref->{first_answer};

in the pg file.

<| Post or View Comments |>