Forums

Search results: 133

WeBWorK Problems -> TF context -> Re: contextTF

by Davide Cervone -
There are a number of other problems with the file as it stands. these include the following:

  1. You aren't using parserAutoStrings.pl or unionLists.pl, so there is no need to load either one.

Your definition of the compoundProblem() is incorrect, since it lists too many parts, and not enough totalAnswers. (There are not 10 parts, and they are many more than 4 total answers.) You also don't need to set parserValues to 1, since you haven't used named answers and so no values are being set from previous parts.

You do not need the Context()->texStrings or Context()->normalStrings, since you are not substituting any MathObjects into the text strings anywhere.

In part 1 you set the context to LeadingZeros and set its reduceConstants flag, but then set the context to LeadingZeros again before creating any MathObjects. That means you lose the reduceConstants that you set.

In part 2, the Context("TF") in the answer section needs to be moved to the beginning of the problem. Where it is now it does nothing, since no MathObjects are created after that, and the earlier String() calls will fail because there is no "T" or "F" in the context that is current at the beginning of the part.

In part 4, the Context("TF") in the answer section is superfluous.

In part 6, the Context(Numeric) is missing the quotation marks around Numeric, and is superfluous since the str_cmp doesn't care about the current context.. As a matter of form, I would prefer to see you use Real() and Formula() in the same way you have used String(): use them when you define the answer, not in the ANS() call. So rather than
    $ans1 = 2;
    ...
    ANS(Real($ans1)->cmp);
I would write
    $ans2 = Real(2);
    ...
    ANS($ans1->cmp);
just as is the case with your true/false answers.

Davide

WeBWorK Problems -> TF context -> Re: contextTF

by Kenneth Appel -
Davide,
I now have a working, but not totally satisfactory version of the problem I want. I will give you the code and then ask a couple of questions.


DOCUMENT();

loadMacros(
"PGstandard.pl", # Standard macros for PG language
"MathObjects.pl",
"compoundProblem.pl",
"unionLists.pl",
"contextLeadingZero.pl",
"contextTF.pl",
"parserAutoStrings.pl",
"contextString.pl",
#"source.pl", # allows code to be displayed on certain sites.
#"PGcourse.pl", # Customization file for the course
);

# Print problem number and point value (weight) for the problem
Context()->texStrings;
TEXT(beginproblem());

# Show which answers are correct and which ones are incorrect
$showPartialCorrectAnswers = 1;

##############################################

$isProfessor = ($studentLogin eq 'kia' || $studentLogin eq 'professor');

#
# Start a compound problem. See the compoundProblem.pl
# file for more details about the parameters you
# can supply.
#
$cp = new compoundProblem(
parts => 10, # the total number of parts in this problem
totalAnswers => 4, # total answers in all parts combined
parserValues => 1, # make parser objects from student answers
allowReset => $isProfessor, # professors get Reset button for testing
);
$part = $cp->part; # look up the current part

##############################################
#
# Part 1
#

if ($part == 1) {

##############################################
##############################################################
#
# Setup
#
#
Context("LeadingZero");
Context()->flags->set(reduceConstants=>0);
$ans1=1000;
$ans2=20;
$a=random (12,36,4);
$ans3=$a/4;
$b= random(2,6,1);
$ans4=10*$b;
##############################################################
#
# Text
#
#

Context()->texStrings;
BEGIN_TEXT
THIS PROBLEM USES A SYSTEM TO PERMIT PROBLEMS IN WHICH A STUDENT CANNOT SEE
LATER PARTS OF THE PROBLEM UNTIL EARLIER PARTS ARE SATISFACTORILY COMPLETED.
THE SYSTEM IS NOT YET FULLY DEVELOPED AND SEVERAL PEOPLE AT DIFFERENT UNIVERSITIES ARE WORKING ON ELIMINATING THE DIFFICULTIES. THEY EXPECT
THAT THE DIFFICULTIES
WILL BE ELIMINATED THIS SUMMER. UNTIL THEN THE PRINCIPAL ANNOYANCE WILL BE THAT
IN LATER PARTS YOU DO NOT HAVE THE OPPORTUNITY TO SUBMIT ANSWERS UNTIL AFTER
BEING TOLD THAT YOU ARE WRONG FOR NOT HAVING SUBMITTING THEN. IF YOU IGNORE THIS
TEMPORARY DIFFICULTY, PROBLEMS OF THIS TYPE WILL BE OTHERWISE CORRECT.
$PAR
The idea of changing units, that is, measuring the same thing using different
units is very important in science.$BR It also presents some ideas
that are very useful in understanding multiplication and division of fractions.
$PAR
First, we will start with a few questions to make sure that you are able to
do such conversions.
$PAR
A packaging plant wants to fill 4000 quarts of milk .$BR
It needs to buy \{ans_rule(3)\} gallons of milk from a dairy farm to do this.
$PAR
Mr. Smith has a five gallon oil container. But he can only buy oil in
quart cans. It will take \{ans_rule(3)\} quarts to fill his oil container.
$PAR
John has $a quarters. He goes to the bank to exchange them for dollar bills.$BR
The bank clerk gives him \{ans_rule(3)\} dollar bills in return.
$PAR
Mary needs dimes for her many stops at parking meters.
She gives the bank clerk $b dollar bills and gets \{ans_rule(3)\} dimes in return.
END_TEXT


Context()->normalStrings;

##############################################################
#
# Answers
#
#
Context("LeadingZero");

ANS(Real($ans1)->cmp );
ANS(Real($ans2)->cmp );
ANS(Real($ans3)->cmp );
ANS(Real($ans4)->cmp );



} # End of Part 1

##############################################
#
# Part 2
#


if ($part == 2) {
Context()->texStrings; #Note the context here
$ans1=String("F");
$ans2=String("F");
$ans3=String("T");
BEGIN_TEXT
Part 2:
$PAR
Now, you should try to understand the pattern of your answers in the first part.
$PAR
For each of the following questions answer
$BR T if the statement is true and
$BR F
if the statement is false.
$PAR
Suppose we have measured something in gallons and we want to find out how many
quarts we have. $BR
We divide the number of gallons by four. [Answer T or F]
\{ans_rule(1)\}
$PAR
Suppose one unit is four times as large (or four times as much) as another
unit. $BR
Then we say that the ratio of the first unit to the second unit is
four.
$BR
More generally, if \(r\) is a number and one unit is \(r\) times as large
as another $BR
then we say that the ratio of the first number to the second
number is \(r\).
$PAR
If a grmph is equal to \(r\) urps and we have 10 grmphs of shampoo then we have
\(10r\) urps of shampoo. \{ans_rule(1)\}
$PAR
If a grmph is equal to \(r\) urps and we have 10 grmphs of shampoo then we have
\(10r\) urps of shampoo. \{ans_rule(1)\}
END_TEXT



##############################################################
#
# Answers
#
#
Context("TF");

ANS($ans1->cmp);
ANS($ans2->cmp);
ANS($ans3->cmp);

} # End of Part 2


##############################################
#
# Part 3
#


if ($part == 3) {


$ans1=2;

$ans2=3;


BEGIN_TEXT
Part 3:
$PIf I have 24 eggs then I have \{ans_rule(1)\} dozen eggs.
$PAR
If a grmph is equal to \(r\) urps and I have 3r urps of shampoo $BR
then I have \{ans_rule(1)\} grmphs of shampoo.
$PAR
If a grmph is equal to \(r\) urps and I have \(s\) grmphs of shampoo $BR
then I have \{ans_rule(5)\} urps of shampoo.
$PAR
If a grmph is equal to \(r\) urps and I have \(t\) urps of shampoo $BR
then I have \{ans_rule(5)\} grmphs of shampoo.
END_TEXT
##############################################################
#
# Answers

Context("LeadingZero");
ANS(Real ($ans1)-> cmp);
ANS(Real ($ans2)-> cmp);


Context("Numeric");
Context()->variables->are(r=>'Real',s=>'Real',t=>'Real');

ANS(Formula("rs")->cmp);
ANS(Formula("t/r")->cmp);
} #end of part 3

##############################################
#
# Part 4
#


if ($part == 4) {

Context("TF"); #Note This works but the context I used in part 2 was rejected
although, as far as I can see the situations are identical. Why?
$ans1=String("F");
$ans2=String("T");
$ans3=String("T");
$ans4=String("F");
$ans5=String("T");
$ans6=String("F");
BEGIN_TEXT
Part 4:
$PAR
Now, let's try to understand the pattern of the things we have seen.
$BR The true-false questions below will check whether you do understand them.
$PAR
Suppose you know that there are 5 zigs in each queep. Use this knowledge in
answering the following questions.
$PAR
If a frammus is 10 zigs then you multiply 10 by 5 to get the
number of queeps in a frammus (answer T or F). \{ans_rule(1)\}
$PAR
If a frammus is 10 zigs then you divide 10 by 5 to get the
number of queeps in a frammus (answer T or F). \{ans_rule(1)\}
$PAR
Each zig is \(\frac {1}{5}\) of a queep (answer T or F). \{ans_rule(1)\}
$PAR
Each zig is 5 queeps (answer T or F). \{ans_rule(1)\}
$PAR
If a greebo is 20 zigs then you multiply 20 by \(\frac {1}{5}\) to get
the number of queeps in a greebo (answer T or F). \{ans_rule(1)\}
$PAR
If a greebo is 20 zigs then you divide 20 by \(\frac {1}{5}\) to get
the number of queeps in a greebo (answer T or F). \{ans_rule(1)\}
END_TEXT
##############################################################
#
# Answers
Context("TF");

ANS($ans1->cmp);
ANS($ans2->cmp);
ANS($ans3->cmp);
ANS($ans4->cmp);
ANS($ans5->cmp);
ANS($ans6->cmp);
} #end of part 4
##############################################
#
# Part 5
#
if ($part == 5) {
$ans1=6;
$ans2=15;
Context()->texStrings;
BEGIN_TEXT
Part 5:
$PAR
In all of the examples in parts 1-4 we have used units in which $BR
one is an integer multiple of another (for example, a gallon is four quarts, a dollar is ten dimes).$BR
Let us look at questions that are a little different.
$PAR
John has a pocketful of quarters but needs 15 dimes. He will have to pay
Mary \{ans_rule(2)\} quarters for the 15 dimes.
$PAR
Road signs in the United states use the approximation that 5 miles is equal
to 8 kilometers.$BR
Using this approximation, 24 kilometers would be approximately \{ans_rule(2)\}miles

END_TEXT
##############################################################
#
# Answers
Context("LeadingZero");
ANS(Real ($ans1)-> cmp);
ANS(Real ($ans2)-> cmp);
} #end of part 5

##############################################
#
# Part 6
#
if ($part == 6) {

Context()->texStrings;
$ans1=6;
$ans2="9/4";
BEGIN_TEXT
Part 6:
$PAR
Now what did you think to yourself when you solved the last two problems?$BR
(You must have solved them or you would not have gotten to this part.)$BR
If you were following the pattern of the previous parts you might have said
$BR
One mile is approximately \(\frac {8}{5}\) kilometers so 24 kilometers is
approximately \(\frac{24}{\frac{8}{5}}\) miles.$BR
or you might have said $BR
One kilometer is approximately \(\frac {5}{8}\) miles so 24 kilometers is
approximately \(\frac{5}{8}\times 24\) miles.
$PAR
But that must mean that multiplying 24 by \(\frac{5}{8}\) gives the same result
as dividing 24 by \(\frac{8}{5}\).$BR
To \(invert\) a fraction means to turn it upside down, like going from \(\frac{8}{5}\) to \(\frac {5}{8}\). $BR
Thus dividing by a fraction is the same as inverting the fraction and multiplying
by the result. $BR
Use this idea to do the problems below.
$PAR \(\frac{2}{\frac{1}{3}}=\) \{ans_rule(1)\}
$PAR \(\frac{3}{\frac{4}{3}}=\) \{ans_rule(3)\}


END_TEXT
##############################################################
#
# Answers

Context("LeadingZero");
ANS( Real($ans1)->cmp);
Context(Numeric);
ANS(str_cmp($ans2));

} #end of part 6
ENDDOCUMENT()
##############################################

Now for the questions.
1. I did not want the answer .4444444 for the last question in part 6. I wanted the answer as a reduced fraction. Clearly I used
an unpleasant kluge. Was there a better way to force fractions?

2. If you look at parts 2 and 4 I have noted what seems to me a lack of parallelism. It appears that the two situations are the same and yet it would
not accept the same context in 4 as I used in 2. Why?

WeBWorK Problems -> TF context -> Re: contextTF

by Kenneth Appel -
Davide,
I tried something that seemed analogous to what you had last shown me and
it did not work. The situation occurs in part3 of the compound problem that had
the TF problem in part 2. Here is the relevant code.

##############################################
#
# Part 3
#


if ($part == 3) {

Context()->texStrings;
$ans1=2;

$ans2=3;
$ans3="sr";
$ans4="t/r";
BEGIN_TEXT
Part 3:
$PAR
If I have 24 eggs then I have \{ans_rule(1)\} dozen eggs.
$PAR
If a grmph is equal to \(r\) urps and I have 3r urps of shampoo $BR
then I have \{ans_rule(1)\} grmphs of shampoo.
$PAR
If a grmph is equal to \(r\) urps and I have \(s\) grmphs of shampoo $BR
then I have \{ans_rule(5)\} urps of shampoo.
$PAR
If a grmph is equal to \(r\) urps and I have \(t\) urps of shampoo $BR
then I have \{ans_rule(5)\} grmphs of shampoo.
END_TEXT
##############################################################
#
# Answers

Context("LeadingZero");
ANS(Real ($ans1)-> cmp);
ANS(Real ($ans2)-> cmp);
Context("String");
ANS(string_cmp($ans3));
ANS(string_cmp($ans4));
} #end of part 3
ENDDOCUMENT()

I tried to use the context String analogously to context TF. I first tried both of
your suggestions for TF but (unless there is an unrelated error causing the
error message) neither worked. The error message was.

String constant 'sr' is not defined in this context at line 6 of (eval 276094) Died within main::String called at line 6 of (eval 276094) from within main::string_cmp called at line 223 of [TMPL]/setteach1/unitchange.pg

Actually, when dealing with a part like this there seems no ideal context.
If I do succeed with any of the contexts I am familiar with, I am sure that I
will at least have to alias rs to sr. Ideally, I would love to see a context
which allows me to define several letters as variables an then work in a version
of numeric or standard numeric. Maybe this is currently possible. Any advice
would be welcomed.
Ken

WeBWorK Problems -> TF context -> Re: contextTF

by Kenneth Appel -
Davide,
I am sending you the code. Please note that I am now working on part 3
and have put an ENDDOCUMENT at the end of part 3. I just move it down as
I proceed. The difficulty is in part 2.
Ken
##DESCRIPTION
## powers extended
##ENDDESCRIPTION
##KEYWORDS('Powers')

## DBsubject('')
## DBchapter('')
## DBsection('')
## Date('')
## Author('')
## Institution('')
## TitleText1('')
## EditionText1('')
## AuthorText1('')
## Section1('')
## Problem1('')

########################################################################

DOCUMENT();

loadMacros(
"PGstandard.pl", # Standard macros for PG language
"MathObjects.pl",
"compoundProblem.pl",
"unionLists.pl",
"contextLeadingZero.pl",
"contextTF.pl",
#"source.pl", # allows code to be displayed on certain sites.
#"PGcourse.pl", # Customization file for the course
);

# Print problem number and point value (weight) for the problem
TEXT(beginproblem());

# Show which answers are correct and which ones are incorrect
$showPartialCorrectAnswers = 1;

##############################################

$isProfessor = ($studentLogin eq 'kia' || $studentLogin eq 'professor');

#
# Start a compound problem. See the compoundProblem.pl
# file for more details about the parameters you
# can supply.
#
$cp = new compoundProblem(
parts => 10, # the total number of parts in this problem
totalAnswers => 4, # total answers in all parts combined
parserValues => 1, # make parser objects from student answers
allowReset => $isProfessor, # professors get Reset button for testing
);
$part = $cp->part; # look up the current part

##############################################
#
# Part 1
#

if ($part == 1) {

##############################################
##############################################################
#
# Setup
#
#
Context("LeadingZero");
Context()->flags->set(reduceConstants=>0);
$ans1=1000;
$ans2=20;
$a=random (12,36,4);
$ans3=$a/4;
$b= random(2,6,1);
$ans4=10*$b;
##############################################################
#
# Text
#
#

Context()->texStrings;
BEGIN_TEXT
THIS PROBLEM USES A SYSTEM TO PERMIT PROBLEMS IN WHICH A STUDENT CANNOT SEE
LATER PARTS OF THE PROBLEM UNTIL EARLIER PARTS ARE SATISFACTORILY COMPLETED.
THE SYSTEM IS NOT YET FULLY DEVELOPED AND SEVERAL PEOPLE AT DIFFERENT UNIVERSITIES ARE WORKING ON ELIMINATING THE DIFFICULTIES. THEY EXPECT THAT THE DIFFICULTIES
WILL BE ELIMINATED THIS SUMMER. UNTIL THEN THE PRINCIPAL ANNOYANCE WILL BE THAT
IN LATER PARTS YOU DO NOT HAVE THE OPPORTUNITY TO SUBMIT ANSWERS UNTIL AFTER
BEING TOLD THAT YOU ARE WRONG FOR NOT HAVING SUBMITTING THEN. IF YOU IGNORE THIS
TEMPORARY DIFFICULTY, PROBLEMS OF THIS TYPE WILL BE OTHERWISE CORRECT.
$PAR
The idea of changing units, that is, measuring the same thing using different
units is very important in science.$BR It also presents some ideas
that are very useful in understanding multiplication and division of fractions.
$PAR
First, we will start with a few questions to make sure that you are able to
do such conversions.
$PAR
A packaging plant wants to fill 4000 quarts of milk .$BR
It needs to buy \{ans_rule(3)\} gallons of milk from a dairy farm to do this.
$PAR
Mr. Smith has a five gallon oil container. But he can only buy oil in
quart cans. It will take \{ans_rule(3)\} quarts to fill his oil container.
$PAR
John has $a quarters. He goes to the bank to exchange them for dollar bills.$BR
The bank clerk gives him \{ans_rule(3)\} dollar bills in return.
$PAR
Mary needs dimes for her many stops at parking meters.
She gives the bank clerk $b dollar bills and gets \{ans_rule(3)\} dimes in return.
END_TEXT


Context()->normalStrings;

##############################################################
#
# Answers
#
#
Context("LeadingZero");

ANS(Real($ans1)->cmp );
ANS(Real($ans2)->cmp );
ANS(Real($ans3)->cmp );
ANS(Real($ans4)->cmp );



} # End of Part 1

##############################################
#
# Part 2
#


if ($part == 2) {
Context()->texStrings;
$ans1="F";
$ans2="T";
$ans3="F";
BEGIN_TEXT
Part 2:
$PAR
Now, you should try to understand the pattern of your answers in the first part.
$PAR
For each of the following questions answer
$BR T if the statement is true and
$BR F
if the statement is false.
$PAR
Suppose we have measured something in gallons and we want to find out how many
quarts we have. $BR

We divide the number of gallons by four. [Answer T or F]
\{ans_rule(1)\}
$PAR
Suppose one unit is four times as large (or four times as much) as another
unit. $BR
Then we say that the ratio of the first unit to the second unit is
four.
$BR
More generally, if \(r\) is a number and one unit is \(r\) times as large
as another $BR
then we say that the ratio of the first number to the second
number is \(r\).
$PAR
If a grmph is equal to \(r\) urps and we have 10 urps of shampoo then we have
\(10r\) grmphs of shampoo. \{ans_rule(1)\}
$PAR
If a grmph is equal to \(r\) urps and we have 10 grmphs of shampoo then we have
\(10r\) urps of shampoo. \{ans_rule(1)\}
END_TEXT
Context()->normalStrings;


##############################################################
#
# Answers
#
#
Context("TF");

ANS(str_cmp($ans1));
ANS(str_cmp($ans2));
ANS(str_cmp($ans3));

} # End of Part 2


##############################################
#
# Part 3
#


if ($part == 3) {

Context()->texStrings;
$ans1=2;

$ans2=3;
BEGIN_TEXT
Part 3:
$PAR
If I have 24 eggs then I have \{ans_rule(1)\} dozen eggs.
$PAR
If a grmph is equal to \(r\) urps and I have 3r uprs of shampoo $BR
then I have \{ans_rule(1)\} grmphs of shampoo.


END_TEXT
##############################################################
#
# Answers

Context("LeadingZero");
ANS(Real ($ans1)-> cmp);
ANS(Real ($ans2)-> cmp);
} #end of part 3
ENDDOCUMENT()
##############################################
#
# Part 4
#


if ($part == 4) {

Context()->texStrings;

BEGIN_TEXT
Part 4:
$PAR
=\{ans_rule(4)\}
END_TEXT
##############################################################
#
# Answers

Context("LeadingZero");
ANS( );

} #end of part 4
##############################################
#
# Part 5
#




WeBWorK Problems -> TF context -> Re: contextTF

by Davide Cervone -
When I type "G" into a T/F answer in the TF context, I get the message:
    Your answer should be one of F or T
just as I would expect. That is part of the contextString.pl functionality, on which contextTF.pl is based.

Perhaps you aren't really using the TF context? Can you include the code you are using so that I can tell if there is a problem with how you are calling the context?

Davide

PS, I have split this discussion off into a separate one, since it has nothing to do with the compound problems in the other discussion.

WeBWorK Problems -> unionTables

by Kenneth Appel -
Davide,
I thought that I had understood how to use unionTables, but seem to be
wrong. What I have here seems essentially the same as something that worked
in another problem, but either I have misunderstood where I can use the
tables or I have made one of my (sad to say) usual errors.

Here is the code
#DESCRIPTION
##Type of
#ENDDESCRIPTION

DOCUMENT();
loadMacros(
"PGstandard.pl",
"PGchoicemacros.pl",
"PGgraphmacros.pl",
"MathObjects.pl",
"compoundProblem.pl",
"contextCurrency.pl",
"contextInequalities.pl",
"contextLeadingZero.pl",
"unionTables.pl",
"unionLists.pl",
"unionMacros.pl",
"contextTF.pl",
);
#for currency use context("Currency") then currency($A);
Context()->texStrings;
TEXT(beginproblem());
$showPartialCorrectAnswers = 1;


$a1=random(10,19,1)/10;
$a2=random(20,29,1)/10;
$a3=random(30,39,1)/10;
$a4=random(40,49,1)/10;
$ans1=String("T");

$b1=random(10,19,1)/10;
$b2=random(20,29,1)/10;
$b3=$b2;
$b4=random(40,49,1)/10;
$ans2=String("T");

$c1=random(10,19,1)/10;
$c2=random(20,29,1)/10;
$c3=random(30,39,1)/10;
$c4=random(40,49,1)/10;
$ans1=String("F");

$d1=random(10,19,1)/10;
$ans1=String("T");

Context()->texStrings;
BEGIN_TEXT
$PAR
For each of the following relation tables answer T if the relation is a function
and F if it is not.
$PAR
\{BeginTable().
AlignedRow ( [, 1, $a1, , 1, $b4, ,1, $c1, ,1 ,$d1],separation=>30,align=>"ri
ght").
AlignedRow ( [, 2, $a2, , 2, $b2, ,2, $c2, ,2 ,$d2],separation=>30,align=>"ri
ght").
AlignedRow ( [, 3, $a3, , 3, $b3, ,2, $c3, ,1 ,$d2],separation=>30,align=>"ri
ght").
AlignedRow ( [, 4, $a4, , 4, $b1, ,4, $c4, ,3 ,$d2],separation=>30,align=>"ri
ght").
AlignedRow([, ans_rule(2), , ans_rule(2),, ans_rule(2),,
ans_rule(2)],align=>"right")
.
EndTable() \}

END_TEXT
Context("TF");

ANS($ans1->cmp);

ENDDOCUMENT()

The display looks like this;

For each of the following relation tables answer T if the relation is a function and F if it is not.

\{

BeginTable(). AlignedRow ( [, 1, 1.9, , 1, 4.9, ,1, 1.1, ,1 ,1.7],separation=>30,align=>"right"). AlignedRow ( [, 2, 2.6, , 2, 2.7, ,2, 2.6, ,2 ,2.3],separation=>30,align=>"right"). AlignedRow ( [, 3, 3, , 3, 2.7, ,2, 3.2, ,1 ,2.3],separation=>30,align=>"right"). AlignedRow ( [, 4, 4.8, , 4, 1.7, ,4, 4.8, ,3 ,2.3],separation=>30,align=>"right"). AlignedRow([, ans_rule(2), , ans_rule(2),, ans_rule(2),, ans_rule(2)],align=>"right") . EndTable()

\}

Ken


WeBWorK Problems -> compound problems -> Re: compound problems

by Davide Cervone -
As you mention, 1 is already true.

Your 2 is certainly planned for the future version. The author will have control over whether students can go back or not, whether previous parts will allow answers to be resubmitted, and whether parts "accumulate" (so they all show at once) or only the active part is shown.

Your 3 is a good suggestion, and I will add it to my list or requests.

See http://webwork.maa.org/moodle/mod/wiki/view.php?id=164 for more about the compound problem plans.

Your comment about going on to the next part is certainly one that I have heard before, but because of he way that WeBWorK works internally, it is not possible to do as you request (at least not without major changes to PG). The reason is that the text of the problem is generated BEFORE the students answers are checked. Indeed, as the problem is processed, the text is created, and at the same time, the correct answers are determined, and the answer checkers are assigned to them. All of that has to be done before the student answers can be checked. Then the answers are checked and the grader is called to determine the final score. Finally, the answer result table is placed at the top of the page.

So the point when we know whether the student's answers are correct or not doesn't occur until after the text of the page is created. The text that shows up must be the text that goes with the answers that are being checked (not the answers for the next part). This is the reason for the second submit. I understand that it is undesirable, but I don't see any practical way around it within WeBWorK's current problem framework.

See http://webwork.maa.org/moodle/mod/forum/discuss.php?d=5834 for more details.

Davide

WeBWorK Problems -> compound problems

by Kenneth Appel -
Davide,
I understand that you plan to modify compoundProblems.pl and hope that
other users and I could make suggestions based on how we plan to write
compound problems. Since the current version was based on the needs of
some users, it might even be desirable to have more than one version when
there are conflicting needs. I realize that it is unlikely that you will be able
to satisfy all wish-lists, but if users provide such lists I hope that it will help
you in designing a product with features that make it more desirable for
many users.

I am now writing problems at the middle school level and use them for
two purposes. One is to introduce students to enrichment material and the other is to provide careful re-introduction to critical material that the users
have not understood. In each case, it is important that the student not be
able to proceed past the section he or she is working on without answering
the questions correctly. But I tend to put material in each section with its
use in later sections in mind and would like the student to be able to refer
back to prior work easily (especially if the compound problem is not finished
in a single sitting).

Ideally, for me, the compound problems should have the following
properties.

1. As is currently the case, students should have no access to the n-th portion
of the problem until he or she has successfully completed all prior portions.

2. The students who are working on the n-th portion should have easy access
to their work on all of the first n portions. (Among other things, this makes
it unnecessary to repeat caveats and the the like). In the best possible world
students should be able to move easily from any portion to any other portions.

3. (less important but desirable to me) The problem writer should be able
to name the parts to make it easier for students to see which prior part is
likely to have the information that they want.

In the current compoundProblem.pl there is at least one undesirable piecesthat I
am sure you already know about, but I will list it just for completeness.
Currently, in order to move to the n-th part upon completion of the n-1-st
the student must submit correct answers but these correct answers do not
allow the student to go on. They just allow the student to get a question
asking whether he or she wants to go on. The student must resubmit answers
along with an affirmative answer to that question in order to go on. If, at
the time answers are submitted a student is allowed to answer the question
of the form: "If this work is correct would you like to proceed to the next
part?", the double step could be eliminated.

Thanks again for your work in writing the current version. I believe that
it is one of the most useful innovations in making WeBWorK a teaching system
in addition its original purpose as a problem presentation and grading system
Ken

Davide,
I decided that I would try first to get the restricted version to work. It is my
impression that I wrote the context as you suggested, but my proofreading is so
dreadful that I can't guarantee that. In any event, in the file contextLeadingZero.pl
is now stored:

[root@homework macros]# more contextLeadingZero.pl
################################################################################

=head1 NAME

contextLeadingZero.pl - implements contextLimitedNumeric with the additional
feature that decimals need integer before decimal pt

=head1 DESCRIPTION

=cut


loadMacros("contextLimitedNumeric.pl");

$context{LeadingZero} = Parser::Context->getCopy("contextLimitedNumeric");
$context{LeadingZero}=>flags->set(
NumberCheck => sub {
my $self = shift;
$self->Error("Decimals must have a number before the decimal point")
if $self->{value_string} =~ m/^\./;
}
);
I embedded this in the problem as shown below (with error message preceding
file listing.

set1: Problem 3

This set is visible to students.

WeBWorK Error

WeBWorK has encountered a software error while attempting to process this problem. It is likely that there is an error in the problem itself. If you are a student, report this error message to your professor to have it corrected. If you are a professor, please consult the error output below for more information.

Error messages

Error detected while loading [PG]/macros/contextLeadingZero.pl: Can't locate object method "set" via package "flags" (perhaps you forgot to load "flags"?) at line 24 of [PG]/macros/contextLeadingZero.pl, chunk 1 Died within main::compile_file called at line 308 of (eval 1122) from within main::loadMacros called at line 6 of [TMPL]/msprobs/mn+o5-1inter13b.pg

Error details

 Problem3
ERROR caught by Translator while processing problem file:msprobs/mn+o5-1inter13b.pg
****************
Error detected while loading [PG]/macros/contextLeadingZero.pl:
Can't locate object method "set" via package "flags" (perhaps you forgot to load "flags"?) at line 24 of [PG]/macros/contextLeadingZero.pl,  chunk 1
 Died within main::compile_file called at line 308 of (eval 1122)
 from within main::loadMacros called at line 6 of [TMPL]/msprobs/mn+o5-1inter13b.pg

****************

------Input Read
1 #DESCRIPTION
2 ##Type of
3 #ENDDESCRIPTION
4
5 DOCUMENT();
6 loadMacros(
7 "PGstandard.pl",
8 "PGchoicemacros.pl",
9 "PGgraphmacros.pl",
10 "MathObjects.pl",
11 "compoundProblem.pl",
12 "contextCurrency.pl",
13 "unionLists.pl",
14 "unionMacros.pl",
15 "contextLimitedNumeric.pl",
16 "contextLeadingZero.pl",
17 );
18 Context()->texStrings;
19 TEXT(beginproblem());
20 $showPartialCorrectAnswers = 1;
21 $a=random(61,69,1);
22 $b=random(31,39,1);
23 $c=random(1,9,1);
24 $ans1= $a/100;
25 $ans2=$b/100;
26 $ans3=$c/100;
27 $ans4=.19;
28 $ans5=.78;
29 Context()->texStrings;
30 BEGIN_TEXT
31 $PAR
32 Write each as a decimal
33 $PAR
34 \( \frac{$a}{100}=\) \{ans_rule(3)\}
35 $PAR
36 \( \frac{$b}{100}= \) \{ans_rule(3)\}
37 $PAR
38 \( \frac{$c}{100}= \) \{ans_rule(2)\}
39 $PAR
40 nineteen hundredths =\{ans_rule(3)\}
41 $PAR
42 seventy-eight hundredths =\{ans_rule(3)\}
43
44 END_TEXT
45 Context("LeadingZero");
46 #note, this should be modified for .xxx
47 &ANS(Real($ans1)->cmp);
48 &ANS(Real($ans2)->cmp);
49 &ANS(Real($ans3)->cmp);
50 &ANS(Real($ans4)->cmp);
51 &ANS(Real($ans5)->cmp);
52
53 ENDDOCUMENT()
Was I supposed to do something about the flags other than what was in the
new context?

Ken,

PS I spent two days at the beach finally reading "Programming Perl" in
more detail (It is amazing how much one can get away with using ordinary
webwork problems with a limited knowledge of Perl) But this one still
eludes me.
Davide,
For some stupid reason my mouse copy would not work on this material
so, after what I thought was careful copying and then two hours of bug checking
on that "careful copying" I got things to compile into the problem. Here is
the code (note the error below the code before reading the code).

DOCUMENT();
loadMacros(
"PGstandard.pl",
"PGchoicemacros.pl",
"PGgraphmacros.pl",
"MathObjects.pl",
"compoundProblem.pl",
"unionLists.pl",
"unionMacros.pl",
"contextInequalities.pl"
);
TEXT(beginproblem());
$showPartialCorrectAnswers = 1;
# A custom checker that compares a student formula to the correct
# formula for identical structure. Both must be two numberes
# separated by an operator.
#
$LimitedOperation = sub {
my($correct,$student,$ans) = @_;
my $f = $ans->{student_formula}{tree};
return 0 if $ans->{message} || $ans->{isPreview} ||
!defined($f);
#
# Check that the form is correct
#
Value->Error("Your answer should be two numbers with
either a +, -, *, or / between them")
unless $f->class eq 'BOP' && isNumber($f->{lop}) &&
isNumber($f->{rop});
#
# Get the student's operands
#
my($a,$b)=($f->{lop}->eval, $f->{rop}->eval);
# Get the correct answer's formula and operands.
#
#my $F = Parser::Formula($ans->{correct_ans})->{tree};
my ($A,$B) =($F->{lop}->eval, $F->{rop}->eval);
#
#Check that the answers are equal, that the operators are
# are the same and that the operands are the same.
#
return $correct == $student &&
$f->{bop} eq $F->{bop} &&
(($A == $a && $B == $b) || ($A == $b && $B == $a));
};
#
# Check if a node is a Number or a negative Number
# (with no operations involved)
#
sub isNumber{
my $n = shift;
return $n->class eq 'Number' ||
($n->class eq 'UOP' && $n->{uop} eq 'u-' &&
$n->{op}->class eq 'Number');
}



Context("Numeric");
$b=random( 4,8,2);
$a=$b*random(3,7,2);
$c=random(20,50,5);
$d1= random(3,7,1);
$a1= random(2,5,1);
$c1=random(4,9,1);
$b1=$c1+$d1*random(3,6,1);
$ans1=Real($a/$b+$c);
$ans2=Compute($a1*($b1-$c1)/$d1);
@vars=('x','y','z');
@nums=('zero ','one ','two ','three ', 'four ', 'five ', 'six ',
'seven ', 'eight ', 'nine ');
@ops=('multiplied by ','divided by ', ' added to ', 'subtracted from ');

$a3=random(6,9,1);
$b3=random(2,5,1);$c3=
random(0,3,1);

if($c3==0){$ans3=Compute("$a3*$b3");}
elsif ($c3==2){$ans3=Compute("$a3+$b3");}
elsif ($c3==3){$ans3=Compute("$a3-$b3");}
else
{Context("LimitedNumeric-StrictFraction");
$ans3=Compute("$a3/$b3");Context("Numeric");}

$a4=random(6,9,1);
$b4=random(2,5,1);
$c4=random(0,3,1);


if($c4==0) {$ans4=Compute("$a4*$b4");}
elsif ($c4==2){$ans4=Compute("$a4+$b4");}
elsif ($c4==3){$ans4=Compute("$a4-$b4");}
else
{Context("LimitedNumeric-StrictFraction");
$ans4=Compute("$a4/$b4");Context("Numeric");}

$m=random(6,10,2);
$n=random(4,8,2);
$p=random(2,5,1);
$nn=random(2,5,1);
$ans5=Real($m+$nn*$n);
$q=random(2,5,1);
$ans6=Compute($m*$n/$q);
$uu=random(5,9,1);
$uuu=random(0,2,1);
$uuuu="$vars[$uuu]";
Context("Inequalities");
$ans7= Compute("$uu<$uuuu");

Context()->texStrings;
BEGIN_TEXT
$PAR
Find the value of each expression

$PAR
\($a\div $b+$c=\) \{ans_rule(4)\}.

$PAR
\($a1( $b1-$c1)\div $d1=\) \{ans_rule(4)\}.
$PAR
Write a numerical expression for each verbal phrase.
$PAR
$nums[$a3] $ops[$c3] $nums[$b3] \{ans_rule(10)\}
$PAR
$nums[$a4] $ops[$c4] $nums[$b4] \{ans_rule(10)\}
$PAR
Evaluate each expression if n=$n, m=$m, p=$p.
$PAR
m+$nn n=\{ans_rule(4)\}.

$PAR
\(\frac{mn}{$q}=\)\{ans_rule(4)\}.

$PAR
Write \( \underline{$nums[$uu]\ less\ than\ $vars[$uuu]}\)
as an algebraic expression: \{ans_rule(7)\}.




END_TEXT

ANS($ans1->cmp);
ANS($ans2->cmp);
ANS($ans3->cmp(checker=>$LimitedOperation));
ANS($ans4->cmp(checker=>$LimitedOperation));
ANS($ans5->cmp);
ANS($ans6->cmp);
ANS($ans7->cmp);


ENDDOCUMENT()

You may notice that I changed nothing but the error message - I thought
that yours was a bit sophisticated for seventh graders. Then I tried some
false and correct answers. It correctly rejected some false answers with
the proper message, but the following puzzles me.


Entered Answer Preview Correct Result Messages
53 incorrect
15 incorrect
32 8\cdot 4 8*4 incorrect An error occurred while checking your answer:
Can't call method "eval" on an undefined value at line 41 of [TMPL]/patsheets/ch1test.pg
28 7\cdot 4 7+4 incorrect An error occurred while checking your answer:
Can't call method "eval" on an undefined value at line 41 of [TMPL]/patsheets/ch1test.pg
18 incorrect
Notice that entered and preview disagree on problems 3 and 4. Also answer
3 should be incorrect and answer 4 should be incorrect (wrong operator)
Ken