## WeBWorK Main Forum

### Web *FORMS* to write custom problems instead of alternate languages like Python...

by Christian Seberino -
Number of replies: 19
I started a thread recently about possibility of using Python for writing problem sets. After thinking more about it and trying to make a problem set that hid as much Perl as possible, I came up with this. (See below).

Notice that a user just has to edit the variables at the top and never edit below the "Do not edit below this line.". Little to no perl needed.

This got me thinking....the next logical step is to simply enter these variable values in a web form! If Webwork had a web form to create custom problems wouldn't that make everyone happy that was clamoring for their own pet language to be supported by WebWork? A web form is essentially language neutral and has no Perl.

Thoughts?

Chris

$answer_value = 6;$answer_units = "m/s";
$answer_format = "";$answer_percent_tolerance = 20;
$question = <<QUESTION_END; Push the file cabinet with a constant acceleration of 2 m / s$$^2$$ for 3 seconds.$BR
By how much did the velocity change during those three seconds?
QUESTION_END

## ==========================================================
## ==========================================================
## Do not edit below this line.
## ==========================================================
## ==========================================================

DOCUMENT();
"PGbasicmacros.pl",
"PGauxiliaryFunctions.pl",
"PGchoicemacros.pl",
"PGgraphmacros.pl",
"PG_CAPAmacros.pl");
## ----------------------------------------------------------------------------

TEXT(beginproblem());
CAPA_import("${CAPA_Tools}Problem"); TEXT(CAPA_EV(<<'END_OF_TEXT'));$question
END_OF_TEXT

## ----------------------------------------------------------------------------

TEXT("$BR", ans_rule(30), "$BR");
ANS(CAPA_ans($answer_value, "unit" =>$answer_units,
"format" => $answer_format, "sig" => "3 PLUS 13", "reltol" =>$answer_percent_tolerance,
"wgt" => $prob_val, "tries" =>$prob_try));
TEXT(CAPA_EV(<<'END_OF_TEXT'));
END_OF_TEXT

## ----------------------------------------------------------------------------
ENDDOCUMENT();

### Re: Web *FORMS* to write custom problems instead of alternate languages like Python...

by D. Brian Walton -
Personally, I find that static problems like this do not capture the real value of a system like WeBWorK and would never use them. At the same time, I recognize that I am a bleeding edge kind of technology user. Some instructors may want to quickly throw together a particular problem and add it to their problem set that is already using WeBWorK and the PG language trappings may scare them away, in spite of the fact that the templates are easy (for those of us who do) to modify. I think what Chris is getting at is that there could be a version of problem authoring that hides NEARLY ALL of the coding aspect and could make the introduction even more painless.

Here is an extension of Chris's idea. I had started a thread some time in the past where I wish that problems could have problem-set level parameters. In other words, the problem could be written in a general way, and when the problem is added to the problem set, the instructor gets to specify the key parameters for the problem. The same problem could even be added multiple times with different parameters.

I say this, because I have several times written problems that are so similar to one another, that it is just a shame that I have to create multiple versions just to change the level of complexity.

Chris's proposal could be a version of this, where the "parameters" might even include the actual problem statement. It might even be possible to allow some randomization by including parameters specifying limits of a random parameter. The problem description could be in a file, and the corresponding template would ask for the file as an input parameter.

- Brian

In reply to D. Brian Walton

### Re: Web *FORMS* to write custom problems instead of alternate languages like Python...

by Christian Seberino -
Brian

Thanks for your input. As a Webwork beginner, I'm curious what features you use that can't be captured in a "static file" such as mine. Are there lots of awesome features I should know about that I'm not using? What are your favorites?

cs

### Re: Web *FORMS* to write custom problems instead of alternate languages like Python...

by D. Brian Walton -
Here is an example of how I would have done your example problem. The key features that I include here are
(1) Randomized problems, where each assigned student has a problem that is generated using a randomly chosen key value, reducing the risk that different students see the identical problem.
(2) Rerandomization -- once the student gets the correct answer, they can request new versions to augment their practice.
(3) MathObjects -- The NumberWithUnits object takes care of the units automatically (although I noticed that unlike many MathObjects, you can not simply multiply two NumberWithUnits objects together since the answer inherits the first operand rather than computing the proper new units). Notice how simple the answer checker is. Also, the use of "texStrings" for the problem and solution display allows the MathObjects to automatically generate "pretty" mathematical notation formatting.
(4) Solutions -- Students can view a solution that also includes the randomly chosen aspects of the problem.

Not illustrated here are some of the computational issues that MathObjects allow, including automatic differentiation, a variety of reduction rules, and a fair amount of available restrictions on what simplifications the student is expected to do with an answer.

############### SAMPLE PROBLEM ################
DOCUMENT();

"PGstandard.pl",
"parserNumberWithUnits.pl",
"problemRandomize.pl",
);

####
# Allow a student to ask for a new version once they get it right.
####
$pr = ProblemRandomize( 'onlyAfterDue'=>0 ); #### # Define the quantities with units. #### # Acceleration will be between 2 and 5 on an increment of 0.2.$a = random(2,5,0.2);
$accel = NumberWithUnits("$a m/s^2");

# Time will be between 2 and 5 but always an integer.
$t = random(2,5);$time = NumberWithUnits("$t s"); # Randomly choose the object to move. @objects = ("a file cabinet", "an office safe", "an anvil", "a bookshelf");$heavyObject = $objects[random(0,3)]; #### # Define the answer as an object with units automatically ####$deltaVelocity = NumberWithUnits("$a*$t m/s");

### I was hoping I could use the following line
### but units are not treated properly now
# $deltaVelocity =$accel * $time; #### # Display the Problem #### TEXT(beginproblem()); Context()->texStrings; BEGIN_TEXT$PAR
Push $heavyObject with a constant acceleration of $$accel$$ for a $$time$$ time interval. By how much did the velocity change?$BR $BR Velocity change: \{ans_rule(15)\} (Remember to include the correct units to your answer.) END_TEXT Context()->normalStrings; ### # Check the Answer ### ANS($deltaVelocity->cmp );

###
# Give the student a custom solution.
###
Context()->texStrings;
BEGIN_SOLUTION
$PAR$BBOLD Solution: $EBOLD$PAR
Because acceleration is the rate of change of a velocity and is constant during
the $$time$$ interval, the change in velocity is simply the product of
acceleration times the length of time interval, $$\Delta v = a \cdot \Delta t = (accel)(time) = deltaVelocity$$.
END_SOLUTION
Context()->normalStrings;

ENDDOCUMENT();
In reply to D. Brian Walton

### Re: Web *FORMS* to write custom problems instead of alternate languages like Python...

by Christian Seberino -
Brian

Douglas Young