I am not sure why I am suddenly thinking about these issues now, but both solutions present pros and cons. Gavin's is spot on what I was looking for, in that I can paste his solution into the problem I described, and also a different problem that deals with quadratic regressions.
However, if I ask follow up questions based on the regressions, it looks like the level of if/then statements could get deep ...
Alex's solution is essentially what I have been doing.
I was trying to figure out a way to pass the student answer back from the answer checker in a global variable, but I think that causes its own set of problems: for example what if the student logged out after having completed the first part of the question and then logged back in. They would have the first part marked correctly, but their answer would no longer be in the global variable I suspect.
These types of issues come up enough that I wonder if there is a generalizable solution.