Forum archive 2000-2006

Arnold K. Pizer - Input from one problem to another

Arnold K. Pizer - Input from one problem to another

by Arnold Pizer -
Number of replies: 0
inactiveTopicInput from one problem to another topic started 6/4/2006; 9:19:09 PM
last post 6/19/2006; 9:33:13 PM
userArnold K. Pizer - Input from one problem to another  blueArrow
6/4/2006; 9:19:09 PM (reads: 662, responses: 2)
From: Richard North <>

Hi Mike and Arnold,

A Chemistry instructor would like students to be able to input lab results one time and then calculate an answer later using that data unique to each student, but she does not want the students to be able to change the original data. So i was wondering if the problems could be linked some way. I see the link in the definition file, but is that only for random variables? Is there a way to pull input from a previous problem? Any ideas you have would be appreciated.

Thanks, rn

<| Post or View Comments |>

userDavide P. Cervone - Re: Input from one problem to another  blueArrow
6/19/2006; 9:33:13 PM (reads: 762, responses: 0)

My initial response to your question was to think that it could not be done without changes to the system, but it turns out that's wrong. On thinking harder about it, I had a couple of ideas about how to approach your problem, and spent the last few days implementing them. As always, I went a little overboard in generalizing it, and things were a bit subtler than I had originally anticipated, but I think the results are good and you may fine one or both useful.

The first method may not be quite what you were looking for. This approach puts both parts of the question into the same problem file, but only shows one part at a time. The student must complete the first part before the second is shown, and when that happens, the first part is no longer available, so the answers can't be changed.

To handle this, I implemented a fairly general-purpose compound-problem library that lets you control the number of parts, how much each is worth, and how the student can progress from one to the next. There were a number of touchy issues to be handled (how to maintain the data for the parts that aren't showing, how to handle the grading properly, how to indicate when the student can go on, etc.), but I think I have it worked out pretty well.

See the examples at for details.

The drawback for this is that both parts are in the same problem, so this works best for problems where both parts can be done one right after the other. It sounds like you may want the first half to be graded and due before the second part. That is still possible with this library (see the file) with a little cleverness. You could have the two-part problem only allow access to the first part until the professor changes a configuration file at which time only the second part is available. (If you wanted the homework set to actually be due before the second part was available, you'd need to reopen the set for the second half.) It's a bit awkward, but works.

The second idea I had was to save the data from the first problem to a file and have the second part read it in. I figured this would require modification to the system (in the form of a new module that could do the file access), but it turns out that that is not necessary. So I implemented another library that allows you to save data from one problem and access it in another.

See for details.

While working on this, I found a bug in the way WeBWorK handles problem graders, and to really make this method work well you need to have the version of pg/lib/WeBWorK/PG/ that includes the fix for this bug (v 1.15 or later). It looks like you might be able to update just this one file if you want (it hadn't been changed in over 10 months, so if your WW installation is newer than that, you can certainly update just that file).

If you don't want to (or can't) update the PG translator, you can still use this approach by changing the AnswerFile::Save call to AnswerFile::Write in the first problem. This disables its ability to save only when the answers are all correct, so you would have to be more careful about checking the incoming data in the second problem (since it could be anything the student typed), but it would still work for getting data from one to the other.

The mechanism of saving the file in this library is a real hack, and the proper way to do this is to use a preloaded perl module rather than a library loaded on the fly. So I made a version that works that way too.

See for details.

Anyway, I think one of these will work for you. Let me know if you need more information on how to make them work. There are comments in the .pl and .pm files that give more details, and the example .pg files should show you how to call them.

Good luck.


<| Post or View Comments |>